'CSC on macos does not list C# 9
I have updated to the latest .NET 5 SDK 5.0.101 but it seems the CSC compiler is unaware of the existence of C# 9. I have tried using C# 9 features (like init-setters) in Visual Studio Code and Visual Studio Mac (also in Rider), and they work, so I know C# 9 is there. However if I run "csc -langversion:?" it only lists up to 8.0. If I explicitly try to set the langversion to 9.0 (or just "9") I get an error like:
Invalid option '9.0' for /langversion. Use '/langversion:?' to list supported values
So I'm wondering if my environment might not be configured correctly. I mean, things seem to be working but I'm a bit confused about the missing lang-version in the output, and wondering if this may indicate some issue with my current install. Any suggestions?
I'm running macos 10.15.7 (Catalina) and as mentioned above have the latest .NET SDK installed.
Solution 1:[1]
There are two runtimes: Mono and Dotnet. Both of them ship with MSBuild and the C# compiler.
When you type Csc I'm guessing you're getting the Mono C# compiler, which hasn't been updated to C# 9 yet.
Both the compiler and MSBuild in dotnet have been updated, so using dotnet build
should work fine.
Also there's the IDE support in Visual Studio Mac (which is different from the command-line build, it has its own MSBuild and C#). The latest Visual Studio Mac (8.8 and later) supports C# 9 as well.
Solution 2:[2]
For those who also facing this problem, one of the solutions is to select proper MSBuild
version. You can do it in IDE preferences (in my case this is Rider). I was missing C# 10 in project properties langversion
selector and after choosing MsBuild
version 17.0 I got it back and all errors in project are gone
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Kirill Osenkov |
Solution 2 | Tropin Alexey |