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?

Sercan
  • 4,739
  • 3
  • 17
  • 36

2 Answers2

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.

Jason Malinowski
  • 18,148
  • 1
  • 38
  • 55
  • To solve this problem, while browsing the forums, I found out that the .NET version used should be specified as `net45` in the `` 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. – Sercan Dec 18 '21 at 01:59
  • 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"](https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8#default-interface-methods) and the program worked fine. At this stage, I tested the `` feature that [@raBinn](https://stackoverflow.com/users/4989243/rabinn) mentioned in his post in the **\*csproj** file, but I realized that it doesn't matter if I use it or not. Thanks. – Sercan Dec 18 '21 at 02:32
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>
Sercan
  • 4,739
  • 3
  • 17
  • 36
raBinn
  • 159
  • 1
  • 11