Using the ruleset file and Rule Set editor to configure analyzers
In this recipe, we will show you how to use the ruleset
file and the Rule Set editor in Visual Studio to configure the per-project severity of analyzer rules, and illustrate how the severity changes are reflected in the live diagnostics in Visual Studio, as well as command-line builds.
Getting ready
You will need to have created and opened a .NET project in Visual Studio 2017 with NuGet-based analyzers installed in the project. Refer to the first recipe in this chapter for installing analyzers in a .NET project.
How to do it...
- Open a C# project, say
ClassLibrary
, with the analyzer NuGet packageSystem.Runtime.Analyzers.nupkg
prerelease version 1.2.0-beta2 installed in it. - Add the following source code to the project and verify that no
CA1813: Avoid unsealed attributes
is fired:
using System; namespace ClassLibrary { [AttributeUsage(AttributeTargets.All)] public class MyAttribute: Attribute { } }
- In the solution explorer...