1

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?

1

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

To solve this problem, while browsing the forums, I found out that the .NET version used should be specified as net45 in the <TargetFramework> property of the .csproj file. I tried this setting but got feedback that .NET Framework 4.5 is not installed on the system. When I wanted to install .NET Framework 4.5, I was informed that .NET Framework 4.5 was already installed. I was confused what to do.
As you stated, I created the project by giving the dotnet new console command in Developer PowerShell in Visual Studio IDE. I tested a few of the examples in the article "What's new in C# 8.0" and the program worked fine. At this stage, I tested the <LangVersion> feature that @raBinn mentioned in his post in the *csproj file, but I realized that it doesn't matter if I use it or not. Thanks.
0

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>

1 Comment

I tried but unfortunately I did not get successful results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.