Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Globally suppress c# compiler warnings

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?

like image 572
pondermatic Avatar asked Feb 08 '09 21:02

pondermatic


People also ask

How do you suppress Code Analysis warnings?

You can suppress violations in code using a preprocessor directive, the #pragma warning (C#) or Disable (Visual Basic) directive to suppress the warning for only a specific line of code. Or, you can use the SuppressMessage attribute.

How do I stop Visual Studio errors?

Suppress specific warnings for Visual C# or F# Or, select the project node and press Alt+Enter. Choose Build, and go to the Errors and warnings subsection. In the Suppress warnings or Suppress specific warnings box, specify the error codes of the warnings that you want to suppress, separated by semicolons.

What is #pragma C#?

C# provides a feature known as the #pragma feature to remove the warnings. Sometimes we declare a variable but do not use the variable anywhere in the entire program so when we debug our code the compiler gives a warning so using the #pragma we can disable these types of warnings.


2 Answers

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.

like image 88
Autodidact Avatar answered Oct 12 '22 16:10

Autodidact


Open the project properties, on the build tab, enter warning IDs you want to surpress in the Suppress warnings: box.

like image 29
AnthonyWJones Avatar answered Oct 12 '22 16:10

AnthonyWJones