Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When do I suppress warnings to source vs. Project Suppression File

I'm working on resolving about 300 warnings and some of the warnings are unnecessary and can be suppressed. However, my question is do I suppress them in the Source - an attribute is added above the method - Or do I suppress them in the GlobalSuppressioins.cs? Is there any guidance for this, if so where?

like image 848
Eric Avatar asked Jul 22 '10 16:07

Eric


People also ask

How do you suppress code Analysis warnings?

If you migrate a project to Visual Studio 2019, you might suddenly be faced with a large number of code analysis warnings. If you aren't ready to fix the warnings, you can suppress all of them by selecting Analyze > Build and Suppress Active Issues.

How do you suppress warnings?

If we don't want to fix the warning, then we can suppress it with the @SuppressWarnings annotation. This annotation allows us to say which kinds of warnings to ignore. While warning types can vary by compiler vendor, the two most common are deprecation and unchecked.


2 Answers

The GlobalSuppression.cs file is for SuppressMessage attributes that cannot be placed in the source files. If a suppression can be placed in a source file it should.

Issues that cannot be placed in the source file are things like "namespaces should have at least five classes". You can't place an attribute on a namespace so it goes in the global suppressions file.

like image 74
Philip Smith Avatar answered Sep 18 '22 10:09

Philip Smith


Some additional information from MSDN:

MSDN - In Source Suppression

"The global suppression file maintains suppressions that are either global-level suppressions or suppressions that do not specify a target. For example, suppressions for assembly level violations are stored in this file. "

like image 37
Pete Whitehead Avatar answered Sep 19 '22 10:09

Pete Whitehead