From 233ccc8fc689abb0b5b10919ee6fef901ec8f2cd Mon Sep 17 00:00:00 2001 From: Adit Sheth Date: Wed, 13 Nov 2024 12:50:26 -0800 Subject: [PATCH 1/2] Fixed bug 43428. --- .../language-reference/configure-language-version.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/csharp/language-reference/configure-language-version.md b/docs/csharp/language-reference/configure-language-version.md index 52d940a02f200..c0277c0b9bbfd 100644 --- a/docs/csharp/language-reference/configure-language-version.md +++ b/docs/csharp/language-reference/configure-language-version.md @@ -22,6 +22,14 @@ If you must specify your C# version explicitly, you can do so in several ways: > > 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. +## Why can't I select a different C# version? + +In Visual Studio, the option to change the language version through the UI may 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. + +For example, changing the target `TFM` (e.g., 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. + +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. + ## Edit the project file You can set the language version in your project file. For example, if you explicitly want access to preview features, add an element like this: From c4890432186dd3f1a5298aa225e4eef5353c31bc Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Thu, 14 Nov 2024 10:25:48 -0500 Subject: [PATCH 2/2] Apply suggestions from code review --- docs/csharp/language-reference/configure-language-version.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/csharp/language-reference/configure-language-version.md b/docs/csharp/language-reference/configure-language-version.md index c0277c0b9bbfd..b93ba493b78c5 100644 --- a/docs/csharp/language-reference/configure-language-version.md +++ b/docs/csharp/language-reference/configure-language-version.md @@ -22,9 +22,9 @@ If you must specify your C# version explicitly, you can do so in several ways: > > 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. -## Why can't I select a different C# version? +## Why you can't select a different C# version in Visual Studio -In Visual Studio, the option to change the language version through the UI may 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. +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. For example, changing the target `TFM` (e.g., 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.