14

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.

Community
  • 1
  • 1
jcollum
  • 43,623
  • 55
  • 191
  • 321
  • I wonder where there's no UI for MSBuild? Seems like it could really use one. Guessing at various settings is a waste of time. – jcollum Nov 30 '10 at 22:10
  • You don't need to guess. Use VS, modify project properties (build tab or code analysis tab), and then see what changes are persisted into the .csproj file. The whole point of msbuild is to be a command-line tool. – Brian Nov 30 '10 at 22:16
  • @Brian: I've looked through the csproj property pages and don't see anything about these code analysis warnings. I think I'm going to give up. Wasting too much time on this. I thought it would be easy, just some command line I was missing. – jcollum Nov 30 '10 at 22:28

6 Answers6

15

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.

David M
  • 71,481
  • 13
  • 158
  • 186
Brian
  • 117,631
  • 17
  • 236
  • 300
  • Yeah, I think that works. But that means finding all of the warning numbers that I'm getting. I'd like to just say "don't care about warnings" and be done with it. – jcollum Nov 30 '10 at 21:41
  • update: tried /p:NoWarn=true and /p:NoWarn=CA1051 -- no good results. Still getting a ton of other warnings. – jcollum Nov 30 '10 at 21:45
  • Also: this: "/p:NoWarn=CA1051;CA1031" resulted in an error: "The term 'CA1031' is not recognized as the name of a cmdlet, etc" ... blerg – jcollum Nov 30 '10 at 21:47
  • /warn applies to csc.exe, not msbuild. I already addressed that in the question. If there's a way to pass that to msbuild I can't find it... – jcollum Nov 30 '10 at 21:49
  • Just edit the suppressed warnings or warning level inside Visual Studio (project properties, build tab), save the project, and then inspect the .csproj file to see what the 'right kind of properties' should look like (e.g. `Value`). Then pass those to msbuild on the command-line with `/p:Name=Value`. – Brian Nov 30 '10 at 21:51
  • You don't put the CA in the NoWarn list, just the number. – Brian Nov 30 '10 at 21:53
  • @Brian: it's a good idea. I just tried it and it didn't work (edited question). Plus that means putting a /p:Name=Value for every warning! Ugh. – jcollum Nov 30 '10 at 21:54
  • Of course, I just realized this applies to warning coming from the C# compiler. It looks like it might be from a separate analysis tool, in which case maybe see here: http://msdn.microsoft.com/en-us/library/ms244717.aspx – Brian Nov 30 '10 at 21:56
  • I think the NoWarn allows ranges (e.g. `1-3000`). – Brian Nov 30 '10 at 21:56
  • (Alternatively, see if there's e.g. some `RunCodeAnalysis` or other similar-ish propery in the project file that you can undo with `/p`.) – Brian Nov 30 '10 at 21:58
  • @Brian: ahh, I see about the CA. Unfortunately the code analysis warnings are coming through whether i use 1031 or CA1031. My opinion of msbuild just keeps getting lower... – jcollum Nov 30 '10 at 21:58
  • This is the current version. Still getting code analysis warnings: `C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe C:\Dev\BigSolution.sln /p:NoWarn=true /p:NoWarn=1-3000 /p:RunCodeAnalysis=false` – jcollum Nov 30 '10 at 22:02
  • Hm, `/p:RunCodeAnalysis=false` is working for me (I just making a tiny repro). Of course I was calling msbuild on the .csproj file, not a .sln, dunno if that matters. – Brian Nov 30 '10 at 22:09
  • I put in "/p:RunCodeAnalysis=Never /p:RunCodeAnalysis=false" and ran the msbuild on a csproj. Still got the errors. I'm using FxCop, maybe you're using something else? – jcollum Dec 01 '10 at 01:30
  • @Brian: It didn't work with ranges (e.g. 1572-1575) - I tested it in VSTS – sɐunıɔןɐqɐp Feb 07 '20 at 10:38
11

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
Shane Fowler
  • 193
  • 1
  • 9
4

Try this:

msbuild.exe C:\Dev\BigSolution.sln /p:WarningLevel=0 /p:RunCodeAnalysis=false
Josh M.
  • 26,437
  • 24
  • 119
  • 200
1

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

stevo...
  • 11
  • 1
0

http://social.msdn.microsoft.com/Forums/en-US/tfsbuild/thread/96b3ea2e-92ed-4483-bbfe-a4dda3231eb9

According to this, it cannot be suppressed.

Madhur Ahuja
  • 22,211
  • 14
  • 71
  • 124
  • Yeah, I read that. It applies to MSBuild warnings. I want to suppress compiler warnings. Edited question. – jcollum Nov 30 '10 at 21:31
0

Looks like it is not possible...

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

Aaron McIver
  • 24,527
  • 5
  • 59
  • 88
  • Applies to some but not all: Things like CS0219 (The variable 'xxxxxx' is assigned but its value is never used) aren't MSBuild errors I think. – jcollum Nov 30 '10 at 21:28
  • That is a compiler warning, not an MSB warning. Are you passing in arguments...have you checked this out...http://social.msdn.microsoft.com/Forums/en-US/msbuild/thread/94ae238b-e755-4023-a6cb-c113df841c82/ – Aaron McIver Nov 30 '10 at 21:32
  • Yes, I've read that. Involves altering the solution, which is why I specified I didn't want to alter the .sln file in the question. What I'm asking for is probably impossible /sadface – jcollum Nov 30 '10 at 21:42
  • So you don't want to alter the project? ie...Ignore warnings within VS for instance...? You just want this behavior to take place during the msbuild? – Aaron McIver Nov 30 '10 at 21:46
  • Have you tried.../property:RunCodeAnalysis=false found here...http://stackoverflow.com/questions/1610938/how-to-specify-codeanalysisrules-in-msbuild-via-commandline – Aaron McIver Nov 30 '10 at 22:12