Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions docs/csharp/language-reference/configure-language-version.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@
title: Configure language version
description: Learn how to override the default C# language version manually. The C# compiler can support any language version up to the version in the installed SDK.
ms.custom: "updateeachrelease"
ms.date: 01/31/2025
ms.date: 01/16/2026
---

# Configure C# language version

The information in this article applies to .NET 5 and above. For UWP projects, see this information in the article on [Choosing a UWP version](/windows/uwp/updates-and-versions/choose-a-uwp-version).
The information in this article applies to .NET 5 and later. For UWP projects, see the article on [Choosing a UWP version](/windows/uwp/updates-and-versions/choose-a-uwp-version).

In Visual Studio, the option to change the language version through the UI is disabled because the default version is aligned with the project's target framework (`TFM`). This default configuration ensures compatibility between language features and runtime support. To change the language version in Visual Studio, change the project's target framework.
[!INCLUDE[csharp-version-note](./includes/initial-version.md)]

In Visual Studio, the option to change the language version through the UI is disabled because the default version aligns with the project's target framework (`TFM`). This default configuration ensures compatibility between language features and runtime support. To change the language version in Visual Studio, change the project's target framework.

For example, changing the target `TFM` (for example, from [.NET 6](https://dotnet.microsoft.com/en-us/download/dotnet/6.0) to [.NET 9](https://dotnet.microsoft.com/en-us/download/dotnet/9.0)) updates the language version accordingly, from C# 10 to C# 13. This approach prevents issues with runtime compatibility and minimizes unexpected build errors due to unsupported language features.

If you need a specific language version that differs from the one automatically selected, refer to the methods in this article to override the default settings directly in the project file.
If you need a specific language version that differs from the one automatically selected, use the methods in this article to override the default settings directly in the project file.

> [!WARNING]
>
> Setting the `LangVersion` element to `latest` is discouraged. The `latest` setting means the installed compiler uses its latest version. The value of `latest` can change from machine to machine, making builds unreliable. In addition, it enables language features that might require runtime or library features not included in the current SDK.
> Don't set the `LangVersion` element to `latest`. The `latest` setting means the installed compiler uses its latest version. The value of `latest` can change from machine to machine, making builds unreliable. In addition, it enables language features that might require runtime or library features not included in the current SDK.

If you must specify your C# version explicitly, you can do so in several ways:

Expand All @@ -32,7 +34,7 @@ If you must specify your C# version explicitly, you can do so in several ways:

## Edit the project file

You can set the language version in your project file. The project file is the `*.csproj` file in the root folder for your project. For example, if you explicitly want access to preview features, add an element like the following example:
Set the language version in your project file. The project file is the `*.csproj` file in the root folder for your project. For example, if you want explicit access to preview features, add an element like the following example:

```xml
<PropertyGroup>
Expand All @@ -44,7 +46,7 @@ The value `preview` uses the latest available preview C# language version your c

## Configure multiple projects

To configure multiple C# projects, you can create a *Directory.Build.props* file, typically in your solution directory, that contains the `<LangVersion>` element. Add the following setting to the *Directory.Build.props* file:
To configure multiple C# projects, create a *Directory.Build.props* file, typically in your solution directory, that contains the `<LangVersion>` element. Add the following setting to the *Directory.Build.props* file:

```xml
<Project>
Expand All @@ -58,13 +60,13 @@ Builds in all subdirectories of the directory containing that file now use the p

> [!NOTE]
>
> The versions for C# and VB are different. Don't use the *Directory.Build.Props* file for a folder where subdirectories contain projects for both languages. The versions don't match.
> The versions for C# and Visual Basic are different. Don't use the *Directory.Build.Props* file for a folder where subdirectories contain projects for both languages. The versions don't match.

## C# language version reference

> [!IMPORTANT]
>
> Using a C# language version newer than the version associated with your target TFM is unsupported.
> Using a C# language version newer than the version associated with your target TFM isn't supported.

The following table shows all current C# language versions. Older compilers might not understand every value. If you install the latest .NET SDK, you have access to everything listed.

Expand Down
8 changes: 5 additions & 3 deletions docs/csharp/language-reference/language-versioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
title: Language versioning
description: Learn about how the C# language version is determined based on your project and the reasons behind that choice.
ms.custom: "updateeachrelease"
ms.date: 09/17/2024
ms.date: 01/16/2026
---

# C# language versioning

The latest C# compiler determines a default language version based on your project's target framework or frameworks. Visual Studio doesn't provide a UI to change the value, but you can change it by editing the *csproj* file. The choice of default ensures that you use the latest language version compatible with your target framework. You benefit from access to the latest language features compatible with your project's target. This default choice also ensures you don't use a language that requires types or runtime behavior not available in your target framework. Choosing a language version newer than the default can cause hard to diagnose compile-time and runtime errors.
The latest C# compiler determines a default language version based on your project's target framework or frameworks. Visual Studio doesn't provide a UI to change the value, but you can change it by editing the *csproj* file. The choice of default ensures that you use the latest language version compatible with your target framework. You benefit from access to the latest language features compatible with your project's target. This default choice also ensures you don't use a language version that requires types or runtime behavior unavailable in your target framework. Choosing a language version newer than the default can cause hard-to-diagnose compile-time and runtime errors.

[!INCLUDE[csharp-version-note](./includes/initial-version.md)]

[C# 14](../whats-new/csharp-14.md) is supported only on .NET 10 and newer versions. [C# 13](../whats-new/csharp-13.md) is supported only on .NET 9 and newer versions. [C# 12](../whats-new/csharp-12.md) is supported only on .NET 8 and newer versions. Using a C# language version newer than the version associated with your target TFM is unsupported.

Check the [Visual Studio platform compatibility](/visualstudio/releases/2022/compatibility#-visual-studio-2022-support-for-net-development) page for details on which .NET versions are supported by versions of Visual Studio. Check the [Mono page for C#](https://www.mono-project.com/docs/about-mono/languages/csharp/) for Mono compatibility with C# versions.
For details on which .NET versions are supported by versions of Visual Studio, see the [Visual Studio platform compatibility](/visualstudio/releases/2026/compatibility#-visual-studio-support-for-net-development) page.

## Defaults

Expand Down
Loading