How to specify the equivalent of /features:strict (of csc.exe) to msbuild.exe or in the .csproj file?

后端 未结 1 899
悲哀的现实
悲哀的现实 2021-01-18 16:29

Introduction

Consider this simple (and bad) C# class:

using System;

namespace N
{
  static class C
  {
    static void M(DateTime d)
    {
      if          


        
相关标签:
1条回答
  • 2021-01-18 17:07

    This flag is supported in csproj file directly, just add:

    <Features>strict</Features>
    

    To the appropriate PropertyGroup in your csproj file, and after build you will see this warning for your code:

    Warning CS8073 The result of the expression is always 'false' since a value of type 'DateTime' is never equal to 'null' of type 'DateTime?'

    If you want to do the same via msbuild command-line interface, just set this property with /p:Features=strict, like this:

    /t:rebuild /p:Configuration=Debug /p:Platform=x64 /p:Features=strict
    
    0 讨论(0)
提交回复
热议问题