Search code examples
visual-studio-2015code-analysisfxcop

Suppress warnings in Visual Studio 2015 for custom code analyzers


In Visual Studio, when you run Code Analysis on a project or solution, you can then right click on the analysis warning/error and choose 'Suppress Message' to insert the SuppressMessageAttribute in your code.

From my own observations, this feature only seems to work for traditional FxCop/Code Analysis warnings.

Is it possible (or is there a Visual Studio extension) to provide similar functionality for the new 2015 Code Analyzers (eg. for custom analysers installed via NuGet)?


Solution

  • Yes it is possible. I am using Visual Studio 2015 with Update 1, and I have two Live Analyzers installed - SonarLint and CodeCracker. In my Error List window, I can right click on any warning and Suppress it in a Suppression File. PFB the screenshots where I have suppressed a warning message from CodeCracker Analyzer into a Global Suppression File.

    Suppress Code Analysis Warnings

    enter image description here

    Also VS 2015 Update 1 provides a great Code Analysis Feature where in you can view the warnings/messages for only your code changes. Selecting ‘Changed Documents’ filter in the Error Window will show the warnings pertaining to only the files where you have made modifications – and hence makes it lot convenient to use.

    This is applicable to any LIVE code analyzers which you can add to your Visual Studio IDE.