Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppressing issues from Roslyn code Analyzers

Is there any way to suppress the issues from the Roslyn Analyzers? I use the instant analyzer project type. And I want to suppress the issues if the user wants it. Also it must be permanent. If I reopen Visual Studio, the same suppression rules must still be applied.

like image 386
Caner Ozden Avatar asked Jan 11 '16 11:01

Caner Ozden


2 Answers

You can ignore warnings/errors from Roslyn analyzers in exactly the same ways as ignoring normal C# compiler warnings:

  • #pragma disable within source code
  • The Project Properties / Build / Errors and Warnings setting
  • The [SuppressMessage] attribute
like image 155
Jon Skeet Avatar answered Oct 20 '22 17:10

Jon Skeet


In Visual Studio 2017 you can disable Roslyn warnings (like IDE0002, IDE0003, etc.) in project properties:

Screenshot

You can directly edit csproj file if neccessary:

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <NoWarn>IDE0002;1701;1702;1705</NoWarn>
  </PropertyGroup>

As you can see you need to write it with IDE prefix (exactly as it is reported by Roslyn). You have to do that for each build configuration (or create new group without Condition). I think it is fastest and most clear way to disable it for whole project.

Pragma works a bit different most likely due to a bug in VS (so I guess it can be changed later).
For example #pragma warning disable IDE0002 will not show Roslyn messages but it will still highlight code (more grayed).

like image 23
Maxim Avatar answered Oct 20 '22 18:10

Maxim