I'm setting up Visual Studio Code to write and learn C#.
I'm not able to find and use the latest version of C# compiler with Visual Studio Code.
Enquiring enquiring my compiler version with the Visual Studio Code terminal command csc -langversion:? brings up the following error message:
csc : The term 'csc' is not recognized as the name of cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
My previous attempts in solving the problem
Having searched intensely, I have found out this:
- When using Visual Studio, this problem doesn't even occur. Visual Studio apparently contains the necessary .NET SDK and compiler and uses it automatically.
- I should locate the csc.exe file and set it as an environment variable path.
The only csc.exe files I find are located in the directory: C:\Windows\Microsoft.NET\Framework64\v x.x.xxxxx with the latest being version being 4.0.30319.
All the instructions I could find suggested using this folder to be set as an environment variable path.
I do that. I now try again in Visual Studio Code: csc -langversion:?
Now I get the following message:
Microsoft (R) Visual C# Compiler version 4.8.4084.0 for C# 5 Copyright (C) Microsoft Corporation. All rights reserved.
This compiler is provided as part of the Microsoft (R) .NET Framework, but only supports language versions up to C# 5, which is no longer the latest version. For compilers that support newer versions of the C# programming language, see http://go.microsoft.com/fwlink/?LinkID=533240
warning CS2008: No source files specified error CS1617: Invalid option '?' for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default"
So the csc.exe I was referring and have set as an environment variable path is outdated. I would, however, like to get all the modern features of C# 9.
I tried again to find the latest compiler from the folder "C:\Program Files\dotnet", but I could only find a folder, "Roslyn", which, to my understanding, refers to the newest versions of csc. I couldn't find any csc.exe in these folders.
The solutions?
Now should I find the latest csc.exe supporting C# 9 from somewhere (where?) and set it up as an environmental variable path?
Or am I on the wrong track here?
Or is the only choice that I give up Visual Studio Code completely and switch to Visual Studio (I wouldn’t want to do that). But that can't be the only solution!
Background information
I am a total beginner to the world of coding.
I have installed the latest version of .NET SDK 5.0.302.
I have installed the following extensions in my Visual Studio Code instance:
- C# (MS)
- .NET Install Tool for Extension Authors (MS),
- C# XML Documentation Comments (Keisuke Kato)
- ilspy-vscode (SharpDevelop Team)
- MSBuild project tools (tintoy)
- REST Client (Huachao Mao)