How to change language version in C# .net core application?

In a C# .NET Core application, you can change the C# language version by modifying the .csproj file or configuring your IDE settings.


1️⃣ Change Language Version in .csproj File (Recommended)

  1. Open your .csproj file in a text editor or IDE.
  2. Add the <LangVersion> element inside <PropertyGroup>, like this: xmlCopyEdit<PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net8.0</TargetFramework> <LangVersion>latest</LangVersion> <!-- Use latest C# version --> </PropertyGroup>
  3. Save the file and rebuild the project:
dotnet build

Available Language Versions

You can specify a specific C# version instead of latest. Here are some options:

VersionLangVersion Value
C# 12 (Latest)latest
C# 1111
C# 1010
C# 99
C# 88
C# 7.37.3
Default Versiondefault

2️⃣ Change Language Version in Visual Studio (For .NET Core)

If you are using Visual Studio, you can change the C# version in project settings:

  1. Right-click the project in Solution Explorer → Click Properties.
  2. Navigate to Build → Click Advanced.
  3. Locate the Language Version dropdown.
  4. Select the desired C# version (e.g., C# 11, latest).
  5. Save and rebuild the project.

3️⃣ Change Language Version via CLI (global.json)

If you have multiple .NET SDKs installed, your project might use an older C# version.
To force it to use a specific version, create a global.json file:

dotnet new globaljson --sdk-version 8.0.100

Or manually create a global.json file in your project folder:

{
"sdk": {
"version": "8.0.100"
}
}

4️⃣ Check Current C# Version

To verify the C# language version in your project, run:

dotnet --version

If you want to check which version of C# your project is using, you can add the following code inside your application:

Console.WriteLine($"C# Version: {System.Runtime.CompilerServices.RuntimeFeature.IsSupported(\"C#12\")}");

Final Step: Rebuild the Project

Once you’ve updated the language version, rebuild your project:

dotnet build

Leave a comment