2009-06-21 89 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年,我相信發佈)或者所有警告爲錯誤)。