Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Global suppression for entire solution (C#)

Does any one of you know a way I'd be able to suppress e.g. CA2000 for an entire solution?

I'm thinking of something like a GlobalSuppressions class with the following line of code:

[assembly: SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope")]

Thanks for your help in advance.

like image 284
GGMU Avatar asked Apr 10 '18 23:04

GGMU


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 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 are global suppressions?

Learn how to compare and revise your contacts and segments against the Global suppression list. The Global suppression list (GSL) is a collection of known bad email addresses and domains, including ISP spam complainants.

How do I ignore a warning in Visual Studio?

Turn off the warning for a project in Visual StudioSelect the Configuration Properties > C/C++ > Advanced property page. Edit the Disable Specific Warnings property to add 4996 . Choose OK to apply your changes.


1 Answers

Global Suppressions can be configured in .editorconfig file.

  1. Create a file called .editorconfig in the root folder of your solution
  2. Open in a text editor
  3. Add root = true in first line
  4. Below that line add the rules to disable
    [*.{cs,vb}]
    dotnet_diagnostic.<Rule_Code>.severity=silent
    

Here is an example .editorconfig file

root = true

[*.{cs,vb}]
dotnet_diagnostic.CA2000.severity=silent

[*.{cs,vb}]
dotnet_diagnostic.MA0004.severity=silent    # Even works with 3rd part rules/analyser 
like image 95
Vijay Nirmal Avatar answered Sep 19 '22 21:09

Vijay Nirmal