Skip to content

Commit 2c67171

Browse files
authored
Merge pull request #2553 from gewarren/rulesets
Add analyzer rule set topic
2 parents 0cd0550 + 373bbc4 commit 2c67171

11 files changed

+117
-33
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
title: Analyzer rule sets
3+
ms.date: 07/20/2018
4+
ms.prod: visual-studio-dev15
5+
ms.technology: vs-ide-code-analysis
6+
ms.topic: conceptual
7+
helpviewer_keywords:
8+
- "analyzers, rule sets"
9+
- "rule sets for analyzers"
10+
author: gewarren
11+
ms.author: gewarren
12+
manager: douge
13+
ms.workload:
14+
- "multiple"
15+
---
16+
# Rule sets for Roslyn analyzers
17+
18+
Predefined rule sets are included with some NuGet analyzer packages. For example, the rule sets that are included with the [Microsoft.CodeAnalysis.FxCopAnalyzers NuGet analyzer package](https://www.nuget.org/packages/Microsoft.CodeAnalysis.FxCopAnalyzers/) (starting in version 2.6.2) enable or disable rules based on their category, such as security, naming, or performance. Using rule sets makes it easy to quickly see only those rule violations that pertain to a particular category of rule.
19+
20+
If you're migrating from legacy "FxCop" static code analysis to Roslyn analyzers, these rule sets enable you to continue using the same rule configurations you used previously.
21+
22+
## Use analyzer rule sets
23+
24+
After you [install a NuGet analyzer package](install-roslyn-analyzers.md), locate the predefined rule set in its *rulesets* directory, for example *%USERPROFILE%\\.nuget\packages\microsoft.codequality.analyzers\<version>\rulesets*. From there, you can drag and drop, or copy and paste, one or more of the rulesets to your Visual Studio project in **Solution Explorer**.
25+
26+
To make a rule set the active rule set for analysis, right-click on the project in **Solution Explorer** and choose **Properties**. In the project property pages, select the **Code Analysis** tab. Under **Run this rule set**, select **Browse**, and then select the desired rule set that you copied to the project directory. Now you only see rule violations for those rules that are enabled in the selected rule set.
27+
28+
You can also [customize a predefined rule set](how-to-create-a-custom-rule-set.md#create-a-custom-rule-set) to your preference. For example, you can change the severity of one or more rules so that violations appear as errors or warnings in the **Error List**.
29+
30+
## Available rule sets
31+
32+
The predefined analyzer rule sets include three rulesets that affect all the rules in the package&mdash;one that enables them all, one that disables them all, and one that honors each rule's default severity and enablement settings:
33+
34+
- AllRulesEnabled.ruleset
35+
- AllRulesDisabled.ruleset
36+
- AllRulesDefault.ruleset
37+
38+
Additionally, there are two rule sets for each category of rules in the package, such as performance or security. One rule set enables all rules for the category, and one rule set honors the default severity and enablement settings for each rule in the category.
39+
40+
The [Microsoft.CodeAnalysis.FxCopAnalyzers NuGet analyzer package](https://www.nuget.org/packages/Microsoft.CodeAnalysis.FxCopAnalyzers/) includes rule sets for the following categories, to match the rule sets available for legacy "FxCop" static code analysis:
41+
42+
- design
43+
- documentation
44+
- maintainability
45+
- naming
46+
- performance
47+
- reliability
48+
- security
49+
- usage
50+
51+
## See also
52+
53+
- [Overview of .NET Compiler Platform analyzers](roslyn-analyzers-overview.md)
54+
- [Install .NET Compiler Platform analyzers](install-roslyn-analyzers.md)
55+
- [Configure and use Roslyn analyzer rules](use-roslyn-analyzers.md)
56+
- [Use rule sets to group code analysis rules](using-rule-sets-to-group-code-analysis-rules.md)

docs/code-quality/ca0063.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,27 @@ ms.workload:
1414
- "multiple"
1515
---
1616
# CA0063
17+
1718
Failed to load rule set file or one of its dependent rule set files.
1819

19-
Failed to load rule set file or one of its dependent rule set files.
20+
Failed to load rule set file or one of its dependent rule set files.
2021

21-
The specified ruleset could not be found or one of the ruleset files included in your ruleset could not be found. Make sure that the all the rulesets included in your ruleset exist on disk and that the appropriate ruleset directories are being specified in your project through the **CodeAnalysisRuleSetDirectories** property of [!INCLUDE[vstecmsbuild](../extensibility/internals/includes/vstecmsbuild_md.md)].
22+
The specified rule set could not be found or one of the rule set files included in your rule set could not be found. Make sure that the all the rule sets included in your rule set exist on disk and that the appropriate rule set directories are being specified in your project through the **CodeAnalysisRuleSetDirectories** property of [!INCLUDE[vstecmsbuild](../extensibility/internals/includes/vstecmsbuild_md.md)].
2223

23-
To debug the error, examine your ruleset file in a text editor. To find the path to the ruleset file, right-click the project in Solution Explorer, click **Properties**, and then click **Code Analysis**. Make sure the ruleset file is selected in **Run this rule set**. The Path to the rule set is listed in the description field.
24+
To debug the error, examine your rule set file in a text editor. To find the path to the rule set file, right-click the project in Solution Explorer, click **Properties**, and then click **Code Analysis**. Make sure the rule set file is selected in **Run this rule set**. The Path to the rule set is listed in the description field.
2425

25-
Examine the **Path** attribute value all the **Include** elements. Include paths can use relative paths to the parent/current ruleset file, environment variables, and absolute paths. For example:
26+
Examine the **Path** attribute value all the **Include** elements. Include paths can use relative paths to the parent/current rule set file, environment variables, and absolute paths. For example:
2627

27-
```
28+
```xml
2829
<Include Path="%PUBLIC%\Documents\RuleSets\alldesign.ruleset" Action="Default" />
2930
<Include Path="..\alldesign.ruleset" Action="Default" />
3031
<Include Path="C:\Rulesets\alldesign.ruleset" Action="Default" />
3132
```
3233

33-
Inspect each of these include paths and verify they are all valid.
34+
Inspect each of these include paths and verify they are all valid.
3435

35-
In some cases, the location of a ruleset can be dependent on an [!INCLUDE[vstecmsbuild](../extensibility/internals/includes/vstecmsbuild_md.md)] property. [!INCLUDE[vstecmsbuild](../extensibility/internals/includes/vstecmsbuild_md.md)] properties cannot be referenced from a ruleset. To work around this issue, specify additional search paths in the **CodeAnalysisRuleSetDirectories** property of [!INCLUDE[vstecmsbuild](../extensibility/internals/includes/vstecmsbuild_md.md)]. In this scenario, specify only the name of the ruleset in the **Path** attribute of the **Include** element.
36+
In some cases, the location of a rule set can be dependent on an [!INCLUDE[vstecmsbuild](../extensibility/internals/includes/vstecmsbuild_md.md)] property. [!INCLUDE[vstecmsbuild](../extensibility/internals/includes/vstecmsbuild_md.md)] properties cannot be referenced from a rule set. To work around this issue, specify additional search paths in the **CodeAnalysisRuleSetDirectories** property of [!INCLUDE[vstecmsbuild](../extensibility/internals/includes/vstecmsbuild_md.md)]. In this scenario, specify only the name of the rule set in the **Path** attribute of the **Include** element.
3637

3738
## See Also
38-
[Code Analysis Application Errors](../code-quality/code-analysis-application-errors.md)
39+
40+
- [Code Analysis Application Errors](../code-quality/code-analysis-application-errors.md)

docs/code-quality/ca0064.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ No analysis was performed because the specified rule set did not contain any FxC
1919

2020
This warning can occur in one of the following situations:
2121

22-
- If you encounter this warning in conjunction with CA0063 warnings, there was an a problem loading your ruleset file. For more information, see the [CA0063](ca0063.md) documentation.
22+
- If you encounter this warning in conjunction with CA0063 warnings, there was a problem loading your rule set file. For more information, see the [CA0063](ca0063.md) article.
2323

24-
- If you encounter this error in conjunction with CA0062 warnings, it most likely that Code Analysis was unable to find the assembly or assemblies that contain the rules specified by the ruleset. For more information, see the [CA0062](ca0062.md) documentation.
24+
- If you encounter this error in conjunction with CA0062 warnings, it most likely that code analysis was unable to find the assembly or assemblies that contain the rules specified by the rule set. For more information, see the [CA0062](ca0062.md) article.
2525

26-
- Otherwise, this warning usually occurs when your ruleset is empty or all of the rules enabled in a child rule set have been disabled. Use the Visual Studio [rule set editor](../code-quality/working-in-the-code-analysis-rule-set-editor.md) to enable some rules in your ruleset.
26+
- Otherwise, this warning usually occurs when your rule set is empty or all of the rules enabled in a child rule set are disabled. Use the Visual Studio [rule set editor](../code-quality/working-in-the-code-analysis-rule-set-editor.md) to enable some rules in your rule set.
2727

2828
## See also
2929

30-
- [Code Analysis Application Errors](../code-quality/code-analysis-application-errors.md)
30+
- [Code analysis application errors](../code-quality/code-analysis-application-errors.md)

docs/code-quality/how-to-configure-code-analysis-for-a-managed-code-project.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ms.workload:
1818
---
1919
# How to: Configure Code Analysis for a Managed Code Project
2020

21-
In Visual Studio, you can choose from a list of code analysis *rule sets* to apply to a managed code project. The default rule set is *Microsoft Minimum Recommended Rules*. You can apply another rule set to a project or to all projects in a solution.
21+
In Visual Studio, you can choose from a list of code analysis [rule sets](../code-quality/rule-set-reference.md)) to apply to a managed code project. By default, the **Microsoft Minimum Recommended Rules** rule set is selected, but you can apply a different rule set if desired. Rule sets can be applied to one or multiple projects in a solution.
2222

2323
> [!TIP]
2424
> For information about how to configure a rule set for ASP.NET web applications, see [How to: Configure Code Analysis for an ASP.NET web Application](../code-quality/how-to-configure-code-analysis-for-an-aspnet-web-application.md).
@@ -70,4 +70,5 @@ By default, all the managed projects of a solution are assigned the *Microsoft M
7070

7171
## See also
7272

73+
- [Code analysis rule set reference](../code-quality/rule-set-reference.md)
7374
- [How to: Configure Code Analysis for an ASP.NET web Application](../code-quality/how-to-configure-code-analysis-for-an-aspnet-web-application.md)

docs/code-quality/how-to-create-a-custom-rule-set.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ manager: douge
1414
ms.workload:
1515
- "multiple"
1616
---
17-
# Custom rule sets
17+
# Customize a rule set
1818

19-
You can create a custom *rule set* to meet specific project needs for code analysis.
19+
You can create a custom rule set to meet specific project needs for code analysis.
2020

2121
## Create a custom rule set
2222

docs/code-quality/managed-minimun-rules-rule-set-for-managed-code.md renamed to docs/code-quality/managed-minimum-rules-rule-set-for-managed-code.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ ms.workload:
1212
- "dotnet"
1313
---
1414
# Managed Minimum Rules rule set for managed code
15-
The Managed Minimum Rules focus on the most critical problems in your code, including potential security holes, application crashes, and other important logic and design errors. You should include this rule set in any custom rule set you create for your projects.
15+
16+
The Managed Minimum rules focus on the most critical problems in your code, including potential security holes, application crashes, and other important logic and design errors. Include this rule set in any custom rule set you create for your projects.
1617

1718
|Rule|Description|
1819
|----------|-----------------|

docs/code-quality/rule-set-reference.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@ ms.workload:
1414
---
1515
# Code analysis rule set reference
1616

17-
When you configure code analysis for managed code projects in Visual Studio, you can choose from a list of built-in *rule sets*. You can either use one of these built-in rule sets, or you can [customize a rule set](../code-quality/how-to-create-a-custom-rule-set.md) to fit your project requirements.
17+
When you configure static code analysis for managed code projects in Visual Studio, you can choose from a list of built-in *rule sets*. You can either use one of these built-in rule sets, or you can [customize a rule set](../code-quality/how-to-create-a-custom-rule-set.md) to fit your project requirements.
1818

19-
The topics in this section describe the built-in rule sets and the rules (or warnings) they contain.
19+
The topics in this section describe the built-in rule sets and the rules (or warnings) they contain.
20+
21+
> [!NOTE]
22+
> The rule sets in this section pertain to static code analysis. For information about rule sets available for Roslyn analyzer packages, see [Use rule sets with Roslyn analyzers](analyzer-rule-sets.md).
23+
24+
- [All Rules rule set](all-rules-rule-set.md)
25+
- [Basic Correctness Rules rule set for managed code](basic-correctness-rules-rule-set-for-managed-code.md)
26+
- [Basic Design Guideline Rules rule set for managed code](basic-design-guideline-rules-rule-set-for-managed-code.md)
27+
- [Extended Correctness Rules rule set for managed code](extended-correctness-rules-rule-set-for-managed-code.md)
28+
- [Extended Design Guidelines Rules rule set for managed code](extended-design-guidelines-rules-rule-set-for-managed-code.md)
29+
- [Globalization Rules rule set for managed code](globalization-rules-rule-set-for-managed-code.md)
30+
- [Managed Minimum Rules rule set for managed code](managed-minimum-rules-rule-set-for-managed-code.md)
31+
- [Managed Recommended Rules rule set for managed code](managed-recommended-rules-rule-set-for-managed-code.md)
32+
- [Mixed Minimum Rules rule set](mixed-minimum-rules-rule-set.md)
33+
- [Mixed Recommended Rules rule set](mixed-recommended-rules-rule-set.md)
34+
- [Native Minimum Rules rule set](native-minimum-rules-rule-set.md)
35+
- [Native Recommended Rules rule set](native-recommended-rules-rule-set.md)
36+
- [Security Rules rule set for managed code](security-rules-rule-set-for-managed-code.md)

docs/code-quality/toc.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
- name: Code analysis documentation
22
href: index.md
33
- name: Overview
4+
expanded: true
45
items:
56
- name: Code analysis for managed code
67
href: code-analysis-for-managed-code-overview.md
@@ -80,16 +81,18 @@
8081
- name: Rule sets
8182
href: using-rule-sets-to-group-code-analysis-rules.md
8283
items:
83-
- name: Rule Sets for Managed Code
84+
- name: Rule sets for analyzer packages
85+
href: analyzer-rule-sets.md
86+
- name: Rule sets for managed code
8487
href: how-to-configure-code-analysis-for-a-managed-code-project.md
8588
items:
86-
- name: Configure Code Analysis for an ASP.NET Web Application
89+
- name: Configure code analysis for an ASP.NET web app
8790
href: how-to-configure-code-analysis-for-an-aspnet-web-application.md
88-
- name: Rule Sets for C++ Code
91+
- name: Rule sets for C++ code
8992
href: using-rule-sets-to-specify-the-cpp-rules-to-run.md
90-
- name: Create a Custom Rule Set
93+
- name: Create a custom rule set
9194
href: how-to-create-a-custom-rule-set.md
92-
- name: Use the Rule Set Editor
95+
- name: Use the rule set editor
9396
href: working-in-the-code-analysis-rule-set-editor.md
9497
- name: Check-in policies
9598
href: how-to-create-or-update-standard-code-analysis-check-in-policies.md
@@ -125,8 +128,8 @@
125128
href: extended-design-guidelines-rules-rule-set-for-managed-code.md
126129
- name: Globalization Rules rule set for managed code
127130
href: globalization-rules-rule-set-for-managed-code.md
128-
- name: Managed Minimun Rules rule set for managed code
129-
href: managed-minimun-rules-rule-set-for-managed-code.md
131+
- name: Managed Minimum Rules rule set for managed code
132+
href: managed-minimum-rules-rule-set-for-managed-code.md
130133
- name: Managed Recommended Rules rule set for managed code
131134
href: managed-recommended-rules-rule-set-for-managed-code.md
132135
- name: Mixed Minimum Rules rule set

docs/code-quality/use-roslyn-analyzers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ The following screenshot shows the same three violations as they appear in the *
7373

7474
You can change the severity of a rule from **Solution Explorer**, or within the *\<projectname>.ruleset* file that is added to the solution after you change the severity of a rule in **Solution Explorer**.
7575

76-
![Ruleset file in Solution Explorer](media/ruleset-in-solution-explorer.png)
76+
![Rule set file in Solution Explorer](media/ruleset-in-solution-explorer.png)
7777

7878
### To set rule severity from Solution Explorer
7979

@@ -93,7 +93,7 @@ You can change the severity of a rule from **Solution Explorer**, or within the
9393

9494
1. In the **Action** column, select the value to open a drop-down list, and select the desired severity from the list.
9595

96-
![Ruleset file open in editor](media/ruleset-file-in-editor.png)
96+
![Rule set file open in editor](media/ruleset-file-in-editor.png)
9797

9898
## Suppress violations
9999

docs/code-quality/using-rule-sets-to-group-code-analysis-rules.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Code analysis rule sets in Visual Studio
2+
title: Code analysis rule sets
33
ms.date: 04/02/2018
44
ms.prod: visual-studio-dev15
55
ms.technology: vs-ide-code-analysis
@@ -20,11 +20,13 @@ When you configure code analysis in Visual Studio, you can choose from a list of
2020

2121
You can customize a rule set by adding or deleting rules, or by changing rule severities to appear as either warnings or errors in the **Error List**. Customized rule sets can fulfill a need for your particular development environment. When you customize a rule set, the rule set editor provides search and filtering tools to help you in the process.
2222

23+
Rule sets are available for [static analysis of managed code](how-to-configure-code-analysis-for-a-managed-code-project.md), [analysis of C++ code](using-rule-sets-to-specify-the-cpp-rules-to-run.md), and [Roslyn analyzers](analyzer-rule-sets.md).
24+
2325
## Rule set format
2426

2527
A rule set is specified in XML format in a *.ruleset* file. Rules, which consist of an ID and an *action*, are grouped by analyzer ID and namespace in the file.
2628

27-
The XML contents of a *.ruleset* file looks similar to this:
29+
The contents of a *.ruleset* file looks similar to this XML:
2830

2931
```xml
3032
<RuleSet Name="Rules for Hello World project" Description="These rules focus on critical issues for the Hello World app." ToolsVersion="10.0">
@@ -48,14 +50,14 @@ The XML contents of a *.ruleset* file looks similar to this:
4850
```
4951

5052
> [!TIP]
51-
> It is easier to [edit a rule set](../code-quality/working-in-the-code-analysis-rule-set-editor.md) in the graphical **Rule Set Editor** than by hand.
53+
> It's easier to [edit a rule set](../code-quality/working-in-the-code-analysis-rule-set-editor.md) in the graphical **Rule Set Editor** than by hand.
5254
53-
The rule set for a project is specified by the `CodeAnalysisRuleSet` property in the Visual Studio project file. For example:
55+
The rule set for a project is specified by the **CodeAnalysisRuleSet** property in the Visual Studio project file. For example:
5456

5557
```xml
5658
<CodeAnalysisRuleSet>HelloWorld.ruleset</CodeAnalysisRuleSet>
5759
```
5860

5961
## See also
6062

61-
- [Code analysis rule set reference](../code-quality/rule-set-reference.md)
63+
- [Code analysis rule set reference](../code-quality/rule-set-reference.md)

docs/code-quality/working-in-the-code-analysis-rule-set-editor.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ ms.workload:
1515
---
1616
# Use the code analysis rule set editor
1717

18-
The code analysis rule set editor lets you specify the rules that are included in a custom rule set, and the severity of rule violations.
18+
The code analysis rule set editor lets you specify the rules that are included in a custom rule set and set the severity of rule violations.
19+
20+
The following table shows the severity options:
1921

2022
|Action (Severity)|Description|
2123
|-|-|

0 commit comments

Comments
 (0)