Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'SuppressMessage' for a whole namespace

I use underscores for my test methods for a better readability and I want to suppress FxCop errors/warnings for the whole test namespace.

How can I achieve this? I played with GlobalSuppressions.cs but nothing worked:

[module: System.Diagnostics.CodeAnalysis.SuppressMessage(     "Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores",     Scope = "namespace", Target = "Company.Product.Tests")]  [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage(     "Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores",     Scope = "namespace", Target = "Company.Product.Tests")] 
like image 964
timmkrause Avatar asked Jul 06 '12 09:07

timmkrause


People also ask

How to add global suppression file c#?

Suppress violations using a global suppression fileFrom the Error List, select the rules you want to suppress, and then right-click and select Suppress > in Suppression File. The Preview Changes dialog opens and shows a preview of the SuppressMessageAttribute attribute that is added to the global suppressions file.

How do you suppress ca1716?

If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule. To disable the rule for a file, folder, or project, set its severity to none in the configuration file.

How do I suppress an error in Visual Studio?

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.


1 Answers

Suppression of a code analysis warning for a namespace and all its descendant symbols is possible since Visual Studio 2019:

[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage(     "Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores",     Justification = "Test methods require underscores for readability."     Scope = "namespaceanddescendants", Target = "Company.Product.Tests")] 

Scope - The target on which the warning is being suppressed. If the target is not specified, it is set to the target of the attribute. Supported scopes include the following:

  • ...

  • namespaceanddescendants - (New for Visual Studio 2019) This scope suppresses warnings in a namespace and all its descendant symbols. The namespaceanddescendants value is only valid for Roslyn analyzers, and is ignored by binary, FxCop-based static analysis.

Suppress code analysis warnings#SuppressMessage attribute @ MS Docs

like image 109
Leniaal Avatar answered Sep 27 '22 21:09

Leniaal