How to enable Nullable Reference Types feature of C# 8.0 for the whole project

In Visual Studio 16.2 (from preview 1) the property name is changed to Nullable, which is simpler and aligns with the command line argument.

Add the following properties to your .csproj file.

<PropertyGroup>
  <Nullable>enable</Nullable>
  <LangVersion>8.0</LangVersion>
</PropertyGroup>

If you’re targeting netcoreapp3.0 or later, you don’t need to specify a LangVersion to enable nullable reference types.


For older Visual Studio versions:

  • From 16.0 preview 2 to 16.1, set NullableContextOptions to enable.
  • In 16.0 preview 1, set NullableReferenceTypes to true.

Leave a Comment