SteinTech
SteinTech

Reputation: 4068

How to configure Visual Studio not to analyse code in a specific file

Is it possible to tell Visual Studio to not analyze a specific file? In this case, GlobalSuppressions.cs. I can't find any setting for it in options.

I'm also trying to avoid messing up my code with suppress statements, so I want to keep GlobalSuppressions.cs, but not analyze it.

Syntax issues in GlobalSuppressions.cs: which I don't need

Upvotes: 1

Views: 71

Answers (2)

Olivier Jacot-Descombes
Olivier Jacot-Descombes

Reputation: 112672

You can use preprocessor directives:

#pragma warning disable IDE0076
CSharpCodeProducingTheWarnings();
#pragma warning restore IDE0076

You can specify a comma delimited list of warnings if you want to suppress more than one warning.

You can also omit the #pragma warning restore to make the suppression active until the end of the file.

Upvotes: 1

Sarkis
Sarkis

Reputation: 370

You can add the following to your root level .editorconfig file:

[yourfile.cs]
# Disable analyzers for a specific file
dotnet_diagnostic.CAxxxx.severity = none

CAxxxx should be replaced with a specific code analyzer rule you want to disable. In your case set it to none for disabling all analyzers on the file.

Hope this helps!


🤞🏼

Upvotes: 2

Related Questions