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

前端 未结 6 1809
庸人自扰
庸人自扰 2020-12-05 03:44

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 n

6条回答
  •  情歌与酒
    2020-12-05 04:07

    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.

    
      ...
      enable
      8.0
    
    

    Note that if you're targeting netcoreapp3.0 or later, you don't need to specify a LangVersion of 8, as that is the default in .NET Core 3.


    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.

提交回复
热议问题