Using C# 8.0 in Core 2.x, .NET Framework and UWP projects
By Fons Sonnemans, 09-jul-2019With 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.
This setting will add a LangVersion property to your .csproj file (line 6).
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.
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).
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.
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
5
Comments
-
NuShrike24 nov 2020 08:50For 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.
-
online job support22 okt 2019 01:44Very Nice Article…..thank you for sharing
-
On job support29 aug 2019 08:17Really this is a very useful blog. Thank you
-
Ritika Goswami19 aug 2019 08:32Superb Information Given Really Valuable And Helpful Blog Thanks For It Keep Sharing https://www.exltech.in/dot-net-training.html
-
Tudor16 jul 2019 01:34About "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.