Home > Software design >  How do I change the C# version in Visual Studio 2019
How do I change the C# version in Visual Studio 2019

Time:09-18

I'm currently writing a project in C# 7.3 but I need to change it to C# 10.0

When I go to my project's properties' advanced build settings, the option to change the language version is disabled. I'm not sure why it's grayed out, but I don't know how to manually change the C# version. If someone could help, that would be great, thanks!

Screenshot of the advanced build settings

CodePudding user response:

Taken directly from the documentation

The compiler determines a default based on these rules:

Target framework version C# language version default
.NET 7.x C# 11
.NET 6.x C# 10
.NET 5.x C# 9.0
.NET Core 3.x C# 8.0
.NET Core 2.x C# 7.3
.NET Standard 2.1 C# 8.0
.NET Standard 2.0 C# 7.3
.NET Standard 1.x C# 7.3
.NET Framework all C# 7.3

C# 10 is supported only on .NET 6 and newer

You haven't provided the target framework for your project. But you likely need to retarget your project to a framework that supports C#10

CodePudding user response:

You can try to edit the .csproj file by adding something like this:

  <PropertyGroup>
    <LangVersion>10.0</LangVersion>
  </PropertyGroup>
  • Related