Visual Studio 2019 project upgrade to C#8 build failed

ZiN*_*NED 1 c# c#-8.0 visual-studio-2019

For one of our projects we're trying to upgrade to use C#8 instead of C#7.1. The upgrade looks like it works, because the compiler looks like it takes C#8 statements (it doesn't mark it as an error). However, when I build the project I get a build failed without any errors showing initially.

The code to test C#8 is of the following lines:

private string TestCSharp8(int x)
{
    return x switch
    {
        0 => "ZERO",
        1 => "ONE",
        2 => "TWO",
        3 => "THREE",
        _ => "OTHER"
    };
}
Run Code Online (Sandbox Code Playgroud)

The IDE is accepting this code and even suggests to reformat it to this when writing an 'old-fashioned' switch statement. However, when I then build the solution I get the following output in the Error List: 在此处输入图片说明

But then the Ouput log shows the following:

在此处输入图片说明

When I look at the build log after I put the Ouput verbosity to detailed, I can see the following errors occur:

1>C:\VisualStudio\Repos\XXX\YYY\ZZZ\Repositories\ABC.cs(301,5,301,6): error CS1597: Semicolon after method or accessor block is not valid
1>C:\VisualStudio\Repos\XXX\YYY\ZZZ\Repositories\ABC.cs(304,1,304,2): error CS1022: Type or namespace definition, or end-of-file expected
1>Done executing task "Csc" -- FAILED.
1>Done building target "CoreCompile" in project "XYZ.csproj" -- FAILED.
Run Code Online (Sandbox Code Playgroud)

In the project file I have set the <LangVersion> to latest. The target framework we're targetting is .NET Framework 4.7.1.

The strange thing is all of this works and builds in another solution we're having.

So, can someone please help me in the right direction on how to fix this? At the moment I don't know where to look for the solution.

mm8*_*mm8 5

文档

.NET Core 3.x.NET Standard 2.1支持 C# 8.0 。

并且

C# 8.0(及更高版本)仅在 .NET Core 3.x 和更新版本上受支持。许多最新功能需要 .NET Core 3.x 中引入的库和运行时功能。