Reputation: 13856
Is there any way 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:
Upvotes: 7
Views: 2752
Reputation: 124
use .editorconfig
file:
[**/Migrations/**.cs]
generated_code = true
dotnet_analyzer_diagnostic.severity = none
or use .csproj
:
<Project>
<ItemGroup>
<Compile Remove="Migrations\**\*.cs" />
<None Include="Migrations\**\*.cs" />
</ItemGroup>
</Project>
Upvotes: 1
Reputation: 949
For me, I wanted to disable the analyzer for EF Core migration .cs
files. Somehow using dotnet_analyzer_diagnostic.severity = none
didn't work. I had to use:
[Migrations/**]
generated_code = true
This is documented here.
Upvotes: 2
Reputation: 23244
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
Upvotes: 7
Reputation: 445
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 )
Upvotes: 0
Reputation: 17195
You can add this snippet at the very beginning of the file:
// <autogenerated />
This suppresses most warnings on that file.
Upvotes: 6