According to the C# 8 announcement video the "nullable reference types" feature can be enabled for the whole project.
But how to enable it for the project? I did not find any new appropriate option in the Project Properties window in Visual Studio 2019 Preview 1.
Can it be enabled for 'legacy' .csproj
projects if the C# language version is changed to 8.0?
To enable Nullable Reference Types for all code in a project, add the following to its .csproj
file:
<PropertyGroup>
<Nullable>enable</Nullable>
</PropertyGroup>
Alternatively open the Project Properties UI, search for nullable and select the option you want:
To enable this in all projects in the solution, add the property to a Directory.Build.props
file instead. You can use such a file to specify other properties across multiple projects too.
If you're targeting a version of .NET earlier than netcoreapp3.0
, you'll also need to set LangVersion
to 8 or higher, as Nullable Reference Types were added in C# 8:
<PropertyGroup>
<Nullable>enable</Nullable>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
For older Visual Studio versions:
NullableReferenceTypes
to true
.NullableContextOptions
to enable
.Nullable
as above.