'VS Code CSC : error CS1617: Invalid option '7.3' for /langversion

I downloaded VS 2017 15.7, .NET Core 2.1.2 and Blazor to try it out. It wasn't working in VS 2017 properly and thought I would try through the dotnet cli and VS Code. Instead I was met with the following error:

CSC : error CS1617: Invalid option '7.3' for /langversion.

In VS, it will run the application show "Loading..." and then nothing. Not sure if the two issues are related

dotnet --info returns the following:

.NET Command Line Tools (2.1.300-preview1-008174)

Product Information:
 Version:            2.1.300-preview1-008174
Commit SHA-1 hash:  b8df89a54f

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17666
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.1.300-preview1-008174\

Microsoft .NET Core Shared Framework Host

  Version  : 2.1.0-preview1-26216-03
  Build    : f2c3216183d20416568a4bbf5bb7d153e826f153


Solution 1:[1]

Your should use the Preview version of VS for trying out Blazor, which is numbered 15.8.x

vs installer

And install the .net core 2.1 RC. 2.1.2 will not cut it.

Solution 2:[2]

Just had this and a Clean, Rebuild fixed the issue for me.

Solution 3:[3]

On VS 2019, I went to project files, changed the target framework to 4.7.2 from 4.6.2, the project build successfully. Then revert back to 4.6.2 and it still builds successfully

Solution 4:[4]

Come October 2020, and I'm on VS 2019 .. and this is my error that caused me to google my way to this post:

CS1617 Invalid option '7.3' for /langversion; must be ISO-1, ISO-2, Default, Latest or a valid version in range 1 to 7.1

FWIW - I'm just working on an old school .NET Framework / ASP.NET / Web API2 project, fwiw, not trying to do anything cool with Standards or Core...

I'm scratching my head because:

  1. It works on my workstation at work
  2. It works on my Azure CI pipeline
  3. So.. why not on my Win 10 pro workstation at home?

Solution

  • I launched the Visual Studio Installer > 2019 > More > Modify screen
  • Switched to Individual Components tab, scrolled down to Code Tools
  • and found this little checkbox needed checking NuGet targets and build tasks enter image description here This was the only thing I could readily discern as different between my 2 workstations at work and home. I presume checking the box made the difference, and not merely the fact that I was forced to close and restart Visual Studio after I had restored the nugets.. but you never know.

Solution 5:[5]

Clean and Rebuild didn't work for me until I closed Visual Studio and deleted the .vs folder then re-opened, cleaned and rebuilt.

Solution 6:[6]

Just ran into this problem as the app worked previously but was recently pulled down from a repo to a new computer. The first issue was a Nuget package not being found and when we fixed that error, this one cropped up. The solution was:

  1. Close Visual Studio
  2. Open solution
  3. Remove the Microsoft.Net.Compilers (as that was deprecated)
  4. Update/Install both the Microsoft.CodeDom.Providers.DotNetCompilerPlatform and Microsoft.Net.Compilers.Toolset to their latest version Nuget installs for Microsoft compiler packages

5. Clean and rebuild solution

My gut is the version mismatch for both of these packages caused an issue with the language option but I have no idea how this cropped up as it was working correctly the last time the project was checked in.

Solution 7:[7]

In my case I had open the solution with a new version of visual studio, then tried to run it with and older one

  1. Open csproj with notepad

  2. Modify LangVersion element

    From

    <LangVersion>7.3</LangVersion>
    

    To

    <LangVersion>6</LangVersion>
    

Use a proper value for you scenario

Solution 8:[8]

I had the same issue with solution in VS 2019. In addition to this error, I had another error for two projects from this solution:

cs0006: c# metadata file could not be found

The fix was to close VS, remove obj-folder from these projects, open solution again and compile.

Solution 9:[9]

In my case the problem was that the Typescript version was set to "2.5 (Unavailable)", in project Properties, tab TypeScript build. I changed to "Use latest available" to fix the problem.

Why was it set to an unavailable version? Because the source files were checked out from an archive, which originated from a VisualStudio on another pc with TS version 2.5. The current PC does not have 2.5, just 4.1.

Solution 10:[10]

You can use one of the 15.7 previews or above. It's a bit pointless to use those now that the 15.7 final is out. You can also use the 15.8 previews as they are incremental on top of that 15.7 final. Visit blazor.net for up to date details of getting started etc.

Solution 11:[11]

I'm on visual studio 2019 and also bump into that error when building an MVC REST Api project. I solve it by reduce framework version to 4.5 (it was on 4.6.1).

Solution 12:[12]

I had the same issue (blank screen when running the app in VS, Invalid option '7.3' from CLI) and I just needed to ugrade version of the SDK. Check this using dotnet --info. 2.1.300-preview1 does not work, you seem to need 2.1.300-rc1 which is available from https://www.microsoft.com/net/download/all

Solution 13:[13]

None of these worked for me. My code would compile without a hitch, but would fail with the above error when I attempted to publish it. To fix it, I found that the file Directory.Build.Props needed editing to

<Project>
 <PropertyGroup>
   <LangVersion>Default</LangVersion>
 </PropertyGroup>
</Project>

Hope someone finds this nugget useful!

Solution 14:[14]

Bkwdesign's answer and this post helped me a little. The latter fixed the problem locally but it failed on my build server with some errors saying something about "GetPathsOfAllDirectoriesAbove()". Before going down that rabbit hole (because there was never an issue with the build on the server), I came to bkwdesign's answer. I didn't follow the whole thing, but just updated VS 2019 and it worked locally. My build server continues to be fine.

Solution 15:[15]

Open your project in VS 2022, as VS 2019 does not support .NET 6.