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

C#asp.net CoreVisual Studio-CodeBlazorC# 7.3

C# Problem Overview


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

C# Solutions


Solution 1 - C#

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

Solution 2 - C#

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 3 - C#

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 4 - C#

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 5 - C#

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 6 - C#

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 7 - C#

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 - C#

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 - C#

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 - C#

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 - C#

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 - C#

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 - C#

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 - C#

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 - C#

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSpydernazView Question on Stackoverflow
Solution 1 - C#AdamView Answer on Stackoverflow
Solution 2 - C#Amit SoodView Answer on Stackoverflow
Solution 3 - C#bkwdesignView Answer on Stackoverflow
Solution 4 - C#RobView Answer on Stackoverflow
Solution 5 - C#Slippery PeteView Answer on Stackoverflow
Solution 6 - C#FloresView Answer on Stackoverflow
Solution 7 - C#The OneView Answer on Stackoverflow
Solution 8 - C#Anastasia GabrielView Answer on Stackoverflow
Solution 9 - C#RolandView Answer on Stackoverflow
Solution 10 - C#Daniel AbbattView Answer on Stackoverflow
Solution 11 - C#AriwibawaView Answer on Stackoverflow
Solution 12 - C#alastairtreeView Answer on Stackoverflow
Solution 13 - C#RazView Answer on Stackoverflow
Solution 14 - C#dev'dView Answer on Stackoverflow
Solution 15 - C#SukhiView Answer on Stackoverflow