Home > Back-end >  Compiling New C# Versions (C# 7.0 Higher) From The Command Line
Compiling New C# Versions (C# 7.0 Higher) From The Command Line

Time:12-18

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?

CodePudding user response:

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.

CodePudding user response:

Try opening the *.csproj file and adding to the <PropertyGroup> tag. I added it to both DEBUG and RELEASE tags.

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
        <PlatformTarget>AnyCPU</PlatformTarget>
        <DebugSymbols>true</DebugSymbols>
        <DebugType>full</DebugType>
        <Optimize>false</Optimize>
        <OutputPath>bin\Debug\</OutputPath>
        <DefineConstants>DEBUG;TRACE</DefineConstants>
        <ErrorReport>prompt</ErrorReport>
        <WarningLevel>4</WarningLevel>
        <Prefer32Bit>false</Prefer32Bit>
        <!-- Using the following property will work. -->
        <LangVersion>8.0</LangVersion>
    </PropertyGroup>
</Project>
  • Related