jcollum
jcollum

Reputation: 46613

how can i suppress all compiler and code analysis warnings from msbuild at the command line?

This has been asked, but wasn't answered. The answer (use /warn:1) doesn't work for msbuild.exe, only csc.exe. Perhaps I'm missing something between csc and msbuild?

I'd like to suppress all compiler warnings and code analysis warnings (e.g. "The variable 'variableNameHere' is assigned but its value ..." or Code Analysis Warning : CA1805 : Microsoft.Performance : ...) when I'm using command line msbuild. I don't want to alter the solution file. There are several hundred warning messages in the very large solution that I'm building -- fixing them is far out of scope for my project.

I tried /v:quiet but that didn't work.

Is there any way to do this via the command line?

Update: this:

C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe C:\Dev\ReallyBigSolution.sln /p:NoWarn=true /p:NoWarn=CA1031

Absolutely doesn't work. I still get hundreds of warnings, including the one I specifically blocked (CA1031).

Using /p:RunCodeAnalysis=Never or /p:RunCodeAnalysis=false apparently doesn't suppress code analysis warnings or errors.

Upvotes: 14

Views: 21033

Answers (7)

Necriis
Necriis

Reputation: 131

I tested all the options (ErrorsOnly, RunCodeAnalysis=False, RunCodeAnalysis=Never, UseRoslynAnalyzers=False, WarningLevel=0) and here's the combo that seems to meet the need:

/clp:ErrorsOnly removes all MsBuild verbosity, including warnings, and raises only errors.

/p:WarningLevel=0 removes warnings from analyzers such as Sonar.

Combining the 2 results in a very clean output, and saves up to 40% in build time:

C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe C:\Dev\ReallyBigSolution.sln /clp:ErrorsOnly /p:WarningLevel=0

or, with the latest versions of msbuild:

C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe C:\Dev\ReallyBigSolution.sln -clp:ErrorsOnly -p:WarningLevel=0

Upvotes: 1

Brian
Brian

Reputation: 118935

Can use nowarn flag on the compiler, which corresponds to <NoWarn> property in the .csproj file. So maybe msbuild /p:NoWarn="37;68" will turn off those warning numbers (haven't tried it).

Or use

http://msdn.microsoft.com/en-us/library/13b90fz7.aspx

to turn off warnings altogether. I don't know the property name offhand, try /p:Warn=0.

Edit: read the comments toward the end; seems like really getting rid of all these warnings isn't possible.

Upvotes: 15

Shane Fowler
Shane Fowler

Reputation: 213

I know this is an old post but it got me on the right track and by adding the following to my msbuild call it suppressed all of the warnings and output as it built the project. I have this in a batch file so the only output I get I believe are the end results and any messages I prompt with echo. The secret was in the /clp switch. So I looked that up and put in all of the ones that supress output. Each one got rid of more but there were still the yellow warnings coming up and when I added the ErrorsOnly switch, there was no more output.

call msbuild /clp:NoSummary;NoItemAndPropertyList;ErrorsOnly /verbosity:quiet /nologo

Upvotes: 13

Josh M.
Josh M.

Reputation: 27831

Try this:

msbuild.exe C:\Dev\BigSolution.sln /p:WarningLevel=0 /p:RunCodeAnalysis=false

Upvotes: 4

stevo...
stevo...

Reputation: 11

I have tried this and cannot suppress the warnings either, unless I list them out on the /NoWarn property for msbuild.exe

Upvotes: 1

Aaron McIver
Aaron McIver

Reputation: 24723

Looks like it is not possible...

Warnings with MSB prefix are thrown by MSBuild. Currently, we can't suppress MSBuild warnings.

Upvotes: 0

Related Questions