You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Continue adding version include
Contributes to #50891
Commit by commit:
- C# Guide root.
* Add all files in the XMLDoc folder
Add the new include file, perform a general edit and freshness pass.
* Add include file in the statements folder
Add the include file in all files in the Statements folder. Perform a general edit and freshness pass.
* build warnings
* Update docs/csharp/language-reference/preprocessor-directives.md
* Fix future dates
---------
Co-authored-by: Meaghan Osagie (Lewis) <[email protected]>
Copy file name to clipboardExpand all lines: docs/csharp/language-reference/configure-language-version.md
+11-9Lines changed: 11 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,22 +2,24 @@
2
2
title: Configure language version
3
3
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.
4
4
ms.custom: "updateeachrelease"
5
-
ms.date: 01/31/2025
5
+
ms.date: 01/16/2026
6
6
---
7
7
8
8
# Configure C# language version
9
9
10
-
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).
10
+
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).
11
11
12
-
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.
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.
13
15
14
16
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.
15
17
16
-
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.
18
+
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.
17
19
18
20
> [!WARNING]
19
21
>
20
-
> 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.
22
+
> 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.
21
23
22
24
If you must specify your C# version explicitly, you can do so in several ways:
23
25
@@ -32,7 +34,7 @@ If you must specify your C# version explicitly, you can do so in several ways:
32
34
33
35
## Edit the project file
34
36
35
-
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:
37
+
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:
36
38
37
39
```xml
38
40
<PropertyGroup>
@@ -44,7 +46,7 @@ The value `preview` uses the latest available preview C# language version your c
44
46
45
47
## Configure multiple projects
46
48
47
-
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:
49
+
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:
48
50
49
51
```xml
50
52
<Project>
@@ -58,13 +60,13 @@ Builds in all subdirectories of the directory containing that file now use the p
58
60
59
61
> [!NOTE]
60
62
>
61
-
> 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.
63
+
> 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.
62
64
63
65
## C# language version reference
64
66
65
67
> [!IMPORTANT]
66
68
>
67
-
> Using a C# language version newer than the version associated with your target TFM is unsupported.
69
+
> Using a C# language version newer than the version associated with your target TFM isn't supported.
68
70
69
71
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.
Copy file name to clipboardExpand all lines: docs/csharp/language-reference/language-versioning.md
+5-3Lines changed: 5 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,16 +2,18 @@
2
2
title: Language versioning
3
3
description: Learn about how the C# language version is determined based on your project and the reasons behind that choice.
4
4
ms.custom: "updateeachrelease"
5
-
ms.date: 09/17/2024
5
+
ms.date: 01/16/2026
6
6
---
7
7
8
8
# C# language versioning
9
9
10
-
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.
10
+
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.
[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.
13
15
14
-
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.
16
+
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.
0 commit comments