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

By Fons Sonnemans, posted on
13598 Views 6 Comments

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

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.

Leave a comment

Blog comments

Tudor

16-Jul-2019 1: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.

On job support

29-Aug-2019 8:17
Really this is a very useful blog. Thank you

online job support

22-Oct-2019 1:44
Very Nice Article…..thank you for sharing

NuShrike

24-Nov-2020 8:50
For UWP, still not fixed in Visual Studio 2019 Preview Version 16.9.0 Preview 1.0, but the manual editing of the project file seems to work. Nullability support works on/off in UWP. Sometimes it recognizes the Nullable type API, sometimes not at all.

TAFF

05-Oct-2021 7:02
Absolutely great post here. It has a lot of key elements that truly makes it work.

TAFF

05-Oct-2021 7:03
Absolutely great post here. It has a lot of key elements that truly makes it work.