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.
Alternatively, if you like using GUIs, open the Project Properties UI, search for nullable and select the option you want:
For older Visual Studio versions:
- From 16.0 preview 2 to 16.1, set
NullableContextOptions
toenable
. - In 16.0 preview 1, set
NullableReferenceTypes
totrue
.