2009-06-21 90 views
74

当从命令行运行MSBuild时,是否有任何方法禁用特定的MSBuild警告(例如MSB3253)?我的构建脚本调用msbuild.exe多方式如下:如何禁止特定的MSBuild警告

msbuild.exe MySolution.sln /t:Rebuild /p:Configuration=Release 

我发现我可以抑制使用其他参数msbuild.exe C#警告(如CS0618):

msbuild.exe MySolution.sln /t:Rebuild /p:Configuration=Release /p:NoWarn=0618 

然而,这种方法不适用于MSBuild警告。也许还有另一个神奇的属性设置?

我正在使用.NET 3.5和VS2008。

回答

28

根据this线程在MSDN论坛MSBuild警告不能被压制。

+13

注意:这个答案对于来自MSBuild的错误(前缀为“MSB”)正确,正如OP所要求的。如果谷歌把你带到这里,并且想要抑制编译器错误(例如“CS2008”),你可以做OP做的事情:`/ p:nowarn = 2008`(剥离数字中的“CS”) – 2013-06-13 18:18:52

+1

你碰巧知道如果这仍然是这样的话? – 2014-03-21 13:12:11

+0

MSDN文档在/ nowarn [这里](http://msdn.microsoft.com/en-us/library/7f28x9z3.aspx)。 Msbuild将其中的部分CoreCompile目标传递给csc.exe。 – 2014-12-01 03:47:06

46

我已经成功与/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 
18

对于MSB3253您可以在项目文件正好被设置为剿警告级别(* .csproj的)导致此类警告。

<PropertyGroup> 
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> 
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> 
    <!-- some code goes here --> 
    <ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch> 
     None 
    </ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch> 
    <!-- some code goes here --> 
    </PropertyGroup> 
6

对于那些现在谷歌搜索这(和我一样):即将到来的MSBuild 15.0终将implement the /NoWarn option抑制特定的警告(以及/WarnAsError对待任何特定的警告(要与Visual Studio 2017年,我相信发布)或者所有警告为错误)。