74

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
6
  • When you just run "csc" what version number does it report? It sounds like some aspect of the VS2017 installation may be broken. Also, when you say you've installed ".NET Core 2.1.2" what exactly do you mean? If you could show the result of dotnet --info that would really help.
    – Jon Skeet
    Commented May 10, 2018 at 6:33
  • Most anything you see being mentioned at the Build conference is Preview stuff and not yet formally released. The current preview version of VS2017 is 15.8. Be careful, this isn't stable enough yet to rely on for your every-day work. Commented May 10, 2018 at 8:32
  • @HansPassant: Thanks :) I get this, just excited to try out some of it out.
    – Spydernaz
    Commented May 10, 2018 at 9:45
  • @DaisyShipton: edited to reflect dotnet --info however ``csc``` gets the following error: 'csc' is not recognized as an internal or external command
    – Spydernaz
    Commented May 10, 2018 at 9:54
  • 2
    Note: for other people hitting this error message, make sure you've updated your target framework to 4.6+ and compiler packages like Microsoft.CodeDom.Providers.DotNetCompilerPlatform to support the language features in C# 7.x
    – KyleMit
    Commented Dec 17, 2018 at 14:33

15 Answers 15

120

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

3
  • There is something that is in my source that got past my git ignore and this solved it for me during clean builds. Clean and Rebuild. My project recently went through a 2017 to 2019 upgrade and it looks like my Test project type is potentially one of two issues this clean and build fixed.
    – Sql Surfer
    Commented Jul 7, 2020 at 17:23
  • Every time I have this problem, I'm faced with the question, "What was the solution again?". And then it's "so simple". Thanks for your feedback. (worked with VS2019 / ASP.NET Solution)
    – Marcus.D
    Commented Oct 13, 2021 at 7:24
  • 2
    It fixes the issue, but then if I Rebuild again immediately afterwards, it comes back. I can only Build/Rebuild successfully after a Clean. Any idea what could be causing that behavior?
    – dev'd
    Commented Dec 15, 2021 at 14:54
30

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.
6
  • 1
    My coworker who tried to build the solution on his company issued workstation was missing one of the .NET core runtimes (even though this wasn't a .NET core app). I exported my Visual Studio config (using the 'more' button in the Visual Studio Installer) and we compared configs to finally figure out why it worked for me and not for him
    – bkwdesign
    Commented Oct 29, 2020 at 15:34
  • 3
    Exact same issue as described above. This worked for me.
    – Dave
    Commented Oct 29, 2020 at 15:38
  • 3
    hah.. on a new PC I just built and googled my way back to my own answer! This time I needed some of the .NET Framework targeting packs
    – bkwdesign
    Commented Jan 14, 2021 at 13:20
  • This fixed it for mine as well. Great job finding that.
    – Darren S
    Commented Jun 10, 2021 at 3:33
  • 1
    Give this guy a medal. Commented Nov 17, 2021 at 21:41
28

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

1
  • 3
    I presume you mean you reverted to 4.7.2?
    – Ruben9922
    Commented Mar 2, 2021 at 11:14
17

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

2
  • In case of troubles with some OLD frameworks I recomend this solution. This solution also worked for me, working on some legacy project still using .NET framework 4.5.2. (don't ask....) I'm using Visual Studio 2022, solution has been building before, but after few updates (and few moths inbetween) it just did not build anymore. Commented May 19, 2022 at 13:53
  • I am working on a legacy project, and deleting the .vs folder worked for me after just a clean and rebuild failed
    – Evert
    Commented Nov 15, 2023 at 10:51
8

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.

1
6

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.

6
  • This Blazor link seems to show that with the latest 2.1 and 15.7 is enough?
    – Spydernaz
    Commented May 10, 2018 at 9:50
  • Okay. 15.7.x was the preview up until some days ago. This blogpost talks about 15.7 Preview, which doesn't exist. So this is confusing. I would advise to test the preview 15.8 it works for me.
    – Flores
    Commented May 10, 2018 at 10:03
  • Also, make sure that that your .net framework is on version 2.1.300-Preview2-8533 or later (which is the RC) 2.1.200 won't work.
    – Flores
    Commented May 10, 2018 at 10:04
  • 1
    Blazor works fine for me with 15.7.0. There's no need for 15.8. You do need the .NET Core 2.1 preview though. The OP's edited question shows that's already installed, although a very slightly earlier preview.
    – Jon Skeet
    Commented May 10, 2018 at 10:17
  • @Flores and @DaisyShipton, Thanks for your help. The preview was not enough. Works on Version: 2.1.0-rc1 Commit: eb9bc92051
    – Spydernaz
    Commented May 10, 2018 at 10:35
3

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.

2

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

1
  • 2
    For me removing that whole line worked too. In my case it seems to have been caused by creating a new project configuration for that particular project in a newer version of Visual Studio, then attempting to rebuild it in an older one.
    – Ruben9922
    Commented Mar 2, 2021 at 12:38
2

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.

0
1

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.

1

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

1

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!

1

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

0
0

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

0

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.