68

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
KyleMit
  • 30,350
  • 66
  • 462
  • 664
Spydernaz
  • 847
  • 2
  • 8
  • 14
  • 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 May 10 '18 at 06: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. – Hans Passant May 10 '18 at 08:32
  • @HansPassant: Thanks :) I get this, just excited to try out some of it out. – Spydernaz May 10 '18 at 09:45
  • @DaisyShipton: edited to reflect ```dotnet --info ``` however ``csc``` gets the following error: 'csc' is not recognized as an internal or external command – Spydernaz May 10 '18 at 09:54
  • It sounds like you've got a slightly older .NET Core 2.1 SDK preview. I suggest you install the rc1 from https://www.microsoft.com/net/download/dotnet-core/sdk-2.1.300-rc1 – Jon Skeet May 10 '18 at 10:19
  • 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`](https://stackoverflow.com/q/42744689/1366033) to support the language features in C# 7.x – KyleMit Dec 17 '18 at 14:33

15 Answers15

104

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

Adam
  • 4,180
  • 2
  • 27
  • 31
  • 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 Jul 07 '20 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 Oct 13 '21 at 07: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 Dec 15 '21 at 14:54
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

Martheen
  • 5,198
  • 4
  • 32
  • 55
Amit Sood
  • 385
  • 3
  • 7
28

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.
bkwdesign
  • 1,953
  • 2
  • 28
  • 50
  • 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 Oct 29 '20 at 15:34
  • 3
    Exact same issue as described above. This worked for me. – Dave Oct 29 '20 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 Jan 14 '21 at 13:20
  • This fixed it for mine as well. Great job finding that. – Darren S Jun 10 '21 at 03:33
  • 1
    Give this guy a medal. – AtLeastTheresToast Nov 17 '21 at 21:41
  • Worked for me on VS2022. Great work. – DasElias Aug 31 '23 at 08:23
15

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

Rob
  • 10,004
  • 5
  • 61
  • 91
  • 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. – Martin Trampus May 19 '22 at 13:53
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.

Slippery Pete
  • 526
  • 5
  • 10
  • I had to leave the Toolset uninstalled, to prevent this issue: https://stackoverflow.com/questions/59276192/getpathsofalldirectoriesabove-cannot-be-evaluated-after-updating-net-framewor – kevinpo Mar 08 '22 at 17:29
5

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.

Flores
  • 8,226
  • 5
  • 49
  • 81
  • This [Blazor](https://learn-blazor.com/getting-started/getting-blazor/) link seems to show that with the latest 2.1 and 15.7 is enough? – Spydernaz May 10 '18 at 09:50
  • Okay. 15.7.x was the preview up until some days ago. [This](https://blogs.msdn.microsoft.com/webdev/2018/05/02/blazor-0-3-0-experimental-release-now-available/) 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 May 10 '18 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 May 10 '18 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 May 10 '18 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 May 10 '18 at 10:35
  • @Spydernaz: Glad it's working - that's still a preview (as opposed to the full GA release), just a later one than you had before. – Jon Skeet May 10 '18 at 10:41
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.

Roland
  • 4,619
  • 7
  • 49
  • 81
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

The One
  • 4,560
  • 5
  • 36
  • 52
  • 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 Mar 02 '21 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.

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

Ariwibawa
  • 627
  • 11
  • 23
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!

Raz
  • 306
  • 3
  • 6
1

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

Rom Eh
  • 1,981
  • 1
  • 16
  • 33
Sukhi
  • 45
  • 1
  • 7
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

alastairtree
  • 3,960
  • 32
  • 49
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.

dev'd
  • 469
  • 1
  • 4
  • 12