Skip to content

Commit 399ea4a

Browse files
Continue adding version include (#51195)
* 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]>
1 parent 3ef9e4f commit 399ea4a

17 files changed

+286
-250
lines changed

docs/csharp/language-reference/configure-language-version.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@
22
title: Configure language version
33
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.
44
ms.custom: "updateeachrelease"
5-
ms.date: 01/31/2025
5+
ms.date: 01/16/2026
66
---
77

88
# Configure C# language version
99

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).
1111

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.
12+
[!INCLUDE[csharp-version-note](./includes/initial-version.md)]
13+
14+
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.
1315

1416
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.
1517

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.
1719

1820
> [!WARNING]
1921
>
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.
2123
2224
If you must specify your C# version explicitly, you can do so in several ways:
2325

@@ -32,7 +34,7 @@ If you must specify your C# version explicitly, you can do so in several ways:
3234
3335
## Edit the project file
3436

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:
3638

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

4547
## Configure multiple projects
4648

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:
4850

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

5961
> [!NOTE]
6062
>
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.
6264
6365
## C# language version reference
6466

6567
> [!IMPORTANT]
6668
>
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.
6870
6971
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.
7072

docs/csharp/language-reference/language-versioning.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
title: Language versioning
33
description: Learn about how the C# language version is determined based on your project and the reasons behind that choice.
44
ms.custom: "updateeachrelease"
5-
ms.date: 09/17/2024
5+
ms.date: 01/16/2026
66
---
77

88
# C# language versioning
99

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.
11+
12+
[!INCLUDE[csharp-version-note](./includes/initial-version.md)]
1113

1214
[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.
1315

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.
1517

1618
## Defaults
1719

0 commit comments

Comments
 (0)