Globally suppress c# compiler warnings
Solution 1
Use the C# commandline option /nowarn http://msdn.microsoft.com/en-us/library/7f28x9z3(VS.80).aspx
To do this within visual studio goto Project properties->Build->(Errors and warnings) Suppress Warnings and then specify a comma separated list of warnings which need to be suppressed.
Solution 2
Open the project properties, on the build tab, enter warning IDs you want to surpress in the Suppress warnings: box.
Solution 3
The VC++ XML tag for this is <DisableSpecificWarnings/> with a semi-colon separated list of numeric IDs. This doesn't appear to be documented anywhere that I can see but FYI.
Related videos on Youtube

Comments
-
pondermatic about 3 years
In my app I have a fair number of entities which have fields which are getting their values set via reflection. (In this case NHibernate is setting them). I'd like to get rid of the "x is never assigned to and will always have its default value 0" warnings, so I can more easily pick out the other warnings. I realize you can surround them in pragma directives, but AFAIK you have to do this for each one. Is there a project wide or solution wide way I could do this?
-
user1703401 over 14 yearsAny reason you wouldn't just put #pragma warning disable 169 at the top of the source code file? It suppresses for the remainder of the file.
-
ShuggyCoUk over 14 years++ to that, much better since it makes it clear that this file contains loads of these and not absolutely everything
-
pondermatic over 14 yearsIn my case I'm using NHibernate to set the IDs of entities. So on every domain object I have private int _ID; I really don't want to have to set put pragma directives on each of the entites, but would rather something global.
-
Mike Nakis over 2 years^^^ not only you should put the pragma directive in each entity, you should actually enable it and disable it on each individual offending assignment in each entity. Stop confusing "less typing" with convenience. Any convenience earned by less typing is paid for later with much more inconvenience and weeping and gnashing of teeth.
-
-
Davut Gürbüz about 11 yearsThat is what I want to do but sadly warning ID's not written with warning in VS2010's error list pane.And some warning IDs are very close but codes are diffrent,I mean CLS error for int and CLS error for a Class name are diffrent.If your coding standart is not CLS what will you do?
-
AnthonyWJones about 11 years@DavutGürbüz: Trying looking in the output window when building
-
Davut Gürbüz about 11 yearsI opened detailed build so its hard to see, but it works, BC40028 disabled most of my CLS warnings thanks
-
J T R almost 11 yearsAs AnthonyWJones points out below, the compiler warning IDs you need to put into this comma separate list are found in the Output window while viewing the Build stream.What isn't mentioned yet in this thread is that they come in the form
CSxxxx
and you must remove the 'CS' prefix in your listed codes in order for it to work. -
Shimmy Weitzhandler about 6 yearsIs there a programmatic way to suppress errors/warnings?
-
wallyk about 5 yearsThis was hard to find in VS2017. In the menu bar choose Project->(project name) Properties... Choose Build tab. Look under Errors and warnings for Suppress warnings: Add the warning numbers in that box.