Home > Software design >  How to Ignore specific file from Visual Studio Warnings Analyzer?
How to Ignore specific file from Visual Studio Warnings Analyzer?

Time:01-18

Is there anyway to suppress all error codes in one specific file?

Surprisingly I couldn't find this. This is pretty common scenario isn't it?

Documentation describes it seems:

  1. we have to disable it line by line or
  2. globally across all files.

https://docs.microsoft.com/en-us/visualstudio/code-quality/in-source-suppression-overview?view=vs-2022#:~:text=You can suppress violations in,can use the SuppressMessage attribute.

CodePudding user response:

You can add this snippet at the very beginning of the file:

// <autogenerated />

This suppresses most warnings on that file.

CodePudding user response:

Use #pragma warning ( push ), then #pragma warning ( disable ), then put your code, then use #pragma warning ( pop ) as described here:

Replace warningCode below with the real codes

 #pragma warning( push )
 #pragma warning( disable : WarningCode)
 //code with warning
 #pragma warning( pop )

CodePudding user response:

Make a section in the .editorconfig file for that given class; specify its file name [{YourClass.cs}] or path [{Folder/YourClass.cs}]in a section and set the severity for all rules to none.

See the All rules scope in the documentation.

[{YourClass.cs}]
dotnet_analyzer_diagnostic.severity = none
  •  Tags:  
  • Related