I'm using Visual Studio 17 (version 15.8.5), my project targets .NET Framework 4.8 and I've tried setting the C# version to use (via Build tab in the Properties window) C# 7.3 (that's the maximum version selectable from the dropdown list). However building the project reports a failure like what in the question title. I've even tried 7.0
and C# latest minor version
, all those report failure as well.
Looks like the environment supports the maximum version of 6 (C# 6.0)?
I've tried installed both Microsoft.Net.Compilers v3.6.0
and Microsoft.Net.Compilers.Toolset v3.6.0
but it changed nothing.
I would like to use the pattern matching feature as the following simple code does:
object o ...
if(o is int c){
//do something with c (cast to int) ...
}
UPDATE:
It's strange that if I create a completely new ASP.NET MVC project , it just compiles OK with C# 7.3 set. So looks like there is something wrong with just the specific project I'm working on. For better diagnosing, I would like to share that project here via this link https://sites.google.com/site/ngaodaantoi/files/WebApiAuth.zip?attredirects=0&d=1
It's recommended that you have VS 2017 to help possibly reproduce the issue.
I resolved this issue wihout upgrading any NuGet packages by following these steps:
Close all open instances of Visual Studio
Open "Visual Studio Installer"
Click "Modify" on the version of Visual Studio you're using
i. In my case, I'm using VS2019 Professional 16.11.0
At the top of the dialog, select the "Individual Components"
In the search bar, type "Roslyn"
Check both options, should look like this
i. In case the image goes down, the options are ".NET Compiler Platform SDK" and "C# and Visual Basic Roslyn Compilers"
ii. In my case, the second one was already checked
Confirm changes by pressing "Modify" at the bottom right of the dialog
Once I reopened my project, I was able to compile successfully.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With