How to suppress specific MSBuild warning

前端 未结 6 1641
悲&欢浪女
悲&欢浪女 2020-11-28 07:03

Is there any way to disable specific MSBuild warning (e.g. MSB3253) when running MSBuild from command line? My build script calls msbuild.exe much the following way:

相关标签:
6条回答
  • 2020-11-28 07:12

    According to this thread in the MSDN Forum MSBuild warnings can't be suppressed.

    0 讨论(0)
  • 2020-11-28 07:15

    For those Googling this now (like me): the upcoming MSBuild 15.0 (to be released with Visual Studio 2017, I presume) will finally implement the /NoWarn option to suppress specific warnings (as well as /WarnAsError to treat either specific warnings or all warnings as errors).

    0 讨论(0)
  • 2020-11-28 07:16

    I've managed to supress the warning level with /p:WarningLevel=X

    msbuild.exe MySolution.sln /t:Rebuild /p:WarningLevel=0 /p:Configuration=Release
                                          ^^^^^^^^^^^^^^^^^
    Warning  
    Level    Meaning
    -------- -------------------------------------------
          0  Turns off emission of all warning messages.
    
          1  Displays severe warning messages
    
          2  Displays level 1 warnings plus certain, less-severe warnings, such
             as warnings about hiding class members
    
          3  Displays level 2 warnings plus certain, less-severe warnings, such 
             as warnings about expressions that always evaluate to true or false
    
          4  (the default) Displays all level 3 warnings plus informational warnings
    
    0 讨论(0)
  • 2020-11-28 07:22

    More recent versions of MSBuild support this via command line (as mentioned by EM0) or with properties:

    <PropertyGroup>
        <MSBuildWarningsAsMessages>$(MSBuildWarningsAsMessages);MSB3253</MSBuildWarningsAsMessages>
    </PropertyGroup>
    

    For details see this comment.

    I didn't find official documentation about this, but it is mentioned in the VerifyFileHash task documentation.

    0 讨论(0)
  • 2020-11-28 07:30

    For MSB3253 you can just set in project file (*.csproj) that cause such warning.

      <PropertyGroup>
        <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
        <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
        <!-- some code goes here -->
        <ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
            None
        </ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
        <!-- some code goes here -->
      </PropertyGroup>
    
    0 讨论(0)
  • 2020-11-28 07:30

    Alternative: Add this to .csproj.

    <PropertyGroup>
      <NoWarn>$(NoWarn);MSB3253</NoWarn>
    </PropertyGroup>
    
    0 讨论(0)
提交回复
热议问题