How do I change the C# version in Visual Studio 2019

Viewed 77

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

3 Answers

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

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

  <PropertyGroup>
    <LangVersion>10.0</LangVersion>
  </PropertyGroup>

C#10 is already the default language version if your target framework is .NET 6, provided you're not overriding it with the LangVersion entry as mentioned in other answers. If you're not targeting .NET 6 or compiling with VS/Build Tools 2022, you'll need to upgrade those first in order to have proper C#10 support.

If you are attempting to set the C# language version manually, keep in mind the default can be overridden in two locations (or programmatically): the project file (aka ProjectName.csproj), or a Directory.Build.props file (for explicitly overriding multiple projects at once). If the aforementioned props file exists, check it as well as your project file to ensure you don't have conflicting entries.

In your case, there's really no reason to manually specify the language version; just upgrade your compiler and use the default. If at that point you still find the project targeting anything < C#10, be aware that the culprit isn't necessarily confined to being the project file.

Related