pondermatic
pondermatic

Reputation: 6583

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?

Upvotes: 31

Views: 21460

Answers (4)

Isaac Baker
Isaac Baker

Reputation: 368

At least in VS2019, you can control solution-level (truly, it's directory-level) warnings in the Directory.Build.Props file by adding the following at the <Project> level:

    <PropertyGroup>
        <NoWarn>MSB3270;MSD3246</NoWarn>
    </PropertyGroup>

Upvotes: 4

Andy Piper
Andy Piper

Reputation: 583

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.

Upvotes: 1

AnthonyWJones
AnthonyWJones

Reputation: 189437

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

Upvotes: 12

Sandeep Datta
Sandeep Datta

Reputation: 29335

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.

Upvotes: 41

Related Questions