Skip to content

Commit 0df77e9

Browse files
committed
Version updates
Fixes #33554: Add a link to selecting the UWP version, because UWP uses a different project format. Fixes #36919: Add that the directory.props.build method should be used only with C# projects, not folders that include both C# and VB projects. Fixes #41296: Move the paragraph that explains why the version dropdown is greyed out to the top of the article.
1 parent 20fb2b1 commit 0df77e9

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ ms.date: 09/17/2024
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.md).
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.
13+
14+
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+
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.
17+
1018
> [!WARNING]
1119
>
1220
> Setting the `LangVersion` element to `latest` is discouraged. The `latest` setting means the installed compiler uses its latest version. That can change from machine to machine, making builds unreliable. In addition, it enables language features that may require runtime or library features not included in the current SDK.
@@ -20,15 +28,7 @@ If you must specify your C# version explicitly, you can do so in several ways:
2028
> [!TIP]
2129
> You can see the language version in Visual Studio in the project properties page. Under the *Build* tab, the *Advanced* pane displays the version selected.
2230
>
23-
> To know what language version you're currently using, put `#error version` (case sensitive) in your code. This makes the compiler report a compiler error, CS8304, with a message containing the compiler version being used and the current selected language version. See [#error (C# Reference)](preprocessor-directives.md#error-and-warning-information) for more information.
24-
25-
## Why you can't select a different C# version in Visual Studio
26-
27-
In Visual Studio, the option to change the language version through the UI might be 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.
28-
29-
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)) will update 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.
30-
31-
If you need a specific language version that differs from the one automatically selected, refer to the methods below to override the default settings directly in the project file.
31+
> To know what language version you're currently using, put `#error version` (case sensitive) in your code. This makes the compiler report a compiler error, CS8304, with a message containing the compiler version being used and the current selected language version. For more information about this pragma, see [#error (C# Reference)](preprocessor-directives.md#error-and-warning-information) for more information.
3232
3333
## Edit the project file
3434

@@ -44,7 +44,7 @@ The value `preview` uses the latest available preview C# language version that y
4444

4545
## Configure multiple projects
4646

47-
To configure multiple 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:
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:
4848

4949
```xml
5050
<Project>
@@ -56,6 +56,10 @@ To configure multiple projects, you can create a *Directory.Build.props* file, t
5656

5757
Builds in all subdirectories of the directory containing that file now use the preview C# version. For more information, see [Customize your build](/visualstudio/msbuild/customize-your-build).
5858

59+
> [!NOTE]
60+
>
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 won't match.
62+
5963
## C# language version reference
6064

6165
> [!IMPORTANT]

0 commit comments

Comments
 (0)