Visual Studio – Not drowning in warning messages with Code Analysis

A quick tip from something I discovered the other day when running a Code Analysis on a solution. There’s a helpful function which will suppress all active issues in a solution and create a suppression file for you.

Why is this useful? If you’ve every joined a team and discovered thousands of warnings when you run an analysis or compiler warnings drowning out the Error List, then it will be a hard sell introducing a static analysis tool into the pipeline. Being able to disable all warnings and only focus on warnings for new code means that Code Analysis can be gradually introduced and rules which have been suppressed can be slowly removed over time.

When you open a solution in Visual Studio, you’ll need to run Code Analysis at least once.

Once the analysis completes, open up the same context menu again and you’ll be presented with a new option to suppress the active issues.

Selecting this option creates a global suppression file in each project and runs the analysis again. Your project will then be cleared of all Code Analysis warnings.

I should point out that C# compiler generated warnings are disabled via #pragma directives directly in the source code.

This might be a good starting point for a project you’re working on.