16

How can I use C# 10 in Visual Studio 2019? I have latest update (16.11.6) and when I try to make a new project (need NET Standard 2.0, for compatibility with 4.7.2) and change it to C#10

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <LangVersion>10.0</LangVersion>
  </PropertyGroup>
</Project>

The IDE will show C#10 features a warning (this is for global usings):

"CS8652: The feature 'global using directive' is currently in Preview and unsupported. To use Preview features, use the 'preview' language version."

When I change the LangVersion to preview, it at least compiles, but my team has a mix of VS2022 and VS 2019 (to be upgraded later), so I am looking for a way to use proper langversion version (I am not comfortable to use preview) that works for all of them.

jahav
  • 699
  • 1
  • 7
  • 24
  • 1
    According to Microsoft .NET6 (C# 10 is part of it) is only supported on VS 2019 for Mac and VS 2022 – HMZ Nov 16 '21 at 13:07
  • You can always use VS 2019 as just an editor. You'll have to build using `dotnet build` after installing the .NET 6 release SDK. Visual Studio doesn't know about the new SDK and will try to use the old one unless you tell it otherwise. Perhaps you can use a `global.json` file for this. Or you may change the MSBUILD path in VS 2019. You'll always run into issues though. Intellisense won't know how to treat C# 10 features and flag them even though the code compiles – Panagiotis Kanavos Nov 16 '21 at 14:01
  • On the other hand, Intellisense is probably the main reason for using VS. If that doesn't work, it's probably better to use eg VS Code. Or you can install VS 2022 Community Edition side-by-side with 2019 – Panagiotis Kanavos Nov 16 '21 at 14:02

1 Answers1

21

According to the documentation C# 10 is only supported on .NET 6.

C# 10 is supported only on .NET 6 and newer versions.

According to the .NET 6 announcement, .NET 6 is only supported in Visual Studio 2022. Not in Visual Studio 2019.

.NET 6 is supported with Visual Studio 2022 and Visual Studio 2022 for Mac. It is not supported with Visual Studio 2019, Visual Studio for Mac 8, or MSBuild 16. If you want to use .NET 6, you will need to upgrade to Visual Studio 2022. .NET 6 is supported with the Visual Studio Code C# extension.

mason
  • 31,774
  • 10
  • 77
  • 121
  • 2
    Doesn't mean you can't edit the `.cs` files or call `dotnet build`. An IDE is a glorified editor after all – Panagiotis Kanavos Nov 16 '21 at 13:47
  • ***What's new*** in _each C# version language_: `C# 5, C# 6, C# 7, C# 8, C# 9., C# 10...` – Kiquenet Nov 22 '22 at 09:28
  • @Kiquenet Are you really asking me that? Do I look like a search engine? Well [here you go anyways](https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-version-history). – mason Nov 22 '22 at 13:29