12

How can I turn on C# preview features in Visual Studio?

The feature 'nullable reference types' is currently in Preview and "unsupported". To use Preview features, use the 'preview' language version.

The project Properties does not offer "unsupported preview of next C# version (preview)" as an option: No preview C sharp preview available

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
SwiftArchitect
  • 47,376
  • 28
  • 140
  • 179
  • 1
    You need VS2019 and a .NETCore project to get the "C# 8.0 beta" choice. Moving to .NETCore is the important part, .NETFramework 4.8 is feature-complete and won't get any goodies anymore, .NET v5.0 is core only. – Hans Passant Jun 17 '19 at 23:51

2 Answers2

6

Synopsis

In order to turn on the preview features, you need all these:

  • Visual Studio preview (recommended)
  • .NET preview (required)
  • Change the Project Application settings
  • Change the Project Build settings

Step by Step

  1. Download Visual Studio 2019 Preview
  2. Download .NET SDK Preview for Visual Studio
  3. Check your installation from a cmd-line:
   > dotnet --list-sdks
   2.1.202 [C:\Program Files\dotnet\sdk]
   …
   2.2.101 [C:\Program Files\dotnet\sdk]
   3.0.100-preview6-012264 [C:\Program Files\dotnet\sdk]
  1. Right-click on your Project → Properties → Application
    Pick the Target Framework (note the link to Install other frameworks… as well) .NET Core 3.0
  2. In Project → Properties → Build Select Advanced… (Advanced Build Settings)
    Select the desired C# version: Unsupported preview of next C sharp version
SwiftArchitect
  • 47,376
  • 28
  • 140
  • 179
  • This assumes the OP wants to use .Net Core 3.0. If the project targets a .Net Framework version, is this still possible? – James Harcourt Jun 18 '19 at 14:25
  • 4
    see @hans-passant comment: C# 8 is only available in .Net Core. – SwiftArchitect Jun 20 '19 at 05:27
  • 3
    In VS 2019 with core 3.1, it says "Automatically Selected based on Framework Version". the only way seems to be to use intellisense features of VS, or add `preview` to the .proj file. – kristianp Oct 08 '20 at 00:01
  • @SwiftArchitect actually no https://stackoverflow.com/questions/56651472/does-c-sharp-8-support-the-net-framework – Anton Apr 29 '21 at 06:52
  • For me the issue was a wrong workingDirectory path in launchSettings.json – Avi Maymon Jun 01 '22 at 11:46
4

I my case I needed to check this checkbox (and restart Visual Studio!)

enter image description here

Julian
  • 33,915
  • 22
  • 119
  • 174