Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid option '7.3' for /langversion; must be ISO-1, ISO-2, Default or an integer in range 1 to 6

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.

like image 690
Hopeless Avatar asked Jul 12 '20 08:07

Hopeless


1 Answers

I resolved this issue wihout upgrading any NuGet packages by following these steps:

  1. Close all open instances of Visual Studio

  2. Open "Visual Studio Installer"

  3. Click "Modify" on the version of Visual Studio you're using

    i. In my case, I'm using VS2019 Professional 16.11.0

  4. At the top of the dialog, select the "Individual Components"

  5. In the search bar, type "Roslyn"

  6. 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

  7. Confirm changes by pressing "Modify" at the bottom right of the dialog

Once I reopened my project, I was able to compile successfully.

like image 57
Justin C Avatar answered Sep 23 '22 10:09

Justin C