Search code examples
c#.netcompiler-errorsroslyncompiler-warnings

Compiling New C# Versions (C# 7.0 Higher) From The Command Line


When I try to compile source code from command line with Microsoft's Visual C# Compiler (v4.8.4084.0), I get the following error and/or warning:

PS C:\> csc Program.cs

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

As part of the Roslyn Project, C# 7.0 language features are currently being developed; but the current version of C# programming language is C# 10. Is there a way to use C# 7.0 higher language features from the command line?


Solution

  • If you install Visual Studio you should get an entry in your start menu for the "developer command prompt". That will have the latest csc and msbuild in your path. You must have added the old (unmaintained) tools to your PATH which is why you're getting that error.