Using C# 8.0 in Core 2.x, .NET Framework and UWP projects

By Fons Sonnemans, 09-jul-2019

With Visual Studio 2019 Preview (currently version 16.2.0 Preview 3.0) you can use C# 8.0 in  .NET Core 3.0 projects. You only have to set the Language version to C# 8.0 (beta) in the Advanced Build Settings. Make sure you do this for 'All configurations' and 'Any CPU', see screenshot below.

Build Settings

This setting will add a LangVersion property to your .csproj file (line 6).

Core 3.0 project file

Core 2.2, .NET Framework and UWP projects

If you try to set the Language version property in a non .NET Core 3.0 project the dropdown doesn't show the C# 8.0 option.

Adevanced Build Settings

You may think it is not possible to use C# 8.0 in these projects. Luckely you still can but you have to add the LangVersion property manually in the .csproj file (line 6). 

Core 2.2 project file

The same also works in .NET Framework projects (ASP.NET, Windows Forms, WPF, Console, Class Library, etc) and UWP projects (line 5 in both screenshots below). You first have to Unload the project before you can Edit it. Reload the project when you are done. You can also edit it in an external text editor.

.NET Framework project file

UWP project file

Unsupported C# 8.0 features

C# 8.0 comes with a lot of new features which are described in the What's new in C# 8.0 documentation. Unfortunately the Default interface members and Indices and ranges features are only supported in .NET Core 3.0 projects. Still there are enough great features to use.

Closure

This workaround is something Microsoft will fix in a new version of Visual Studio. I expect it will be released together with .NET Core 3.0 on the .NET Conf 2019 (online) event (September 23 — 25, 2019). C# 8.0 is now still in Beta, please don't use if in your production code. Have fun with the new features.

Fons

Leave a Comment

Leave a Comment
Name
Comment
5 + 1 =

1 Comments

  • Tudor
    16 jul 2019 01:34
    About "This workaround is something Microsoft will fix in a new version of Visual Studio" - they announced that C# 8.0 will officially supported only on .NET Core >= 3.0, not on .NET 'full' Framework (<= 4.8), that won't be developed further.. :( On .NET Framework only this workaround will be possible, as far as I understood.

All postings/content on this blog are provided "AS IS" with no warranties, and confer no rights. All entries in this blog are my opinion and don't necessarily reflect the opinion of my employer or sponsors. The content on this site is licensed under a Creative Commons Attribution By license.