Working in the Code Analysis Rule Set Editor

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at Working in the Code Analysis Rule Set Editor.

The Code Analysis rule set editor enables you to specify the rules that are included in a custom rule set and to specify the action. You can also specify the action to take when code analysis encounters a violation of the rule.

ActionDescription
WarningGenerates a warning in the Error List window.
ErrorGenerates an error in the Error List window.
NoneDisables the rule.

The editor displays the rules in a tree structure that groups the rules by a rule set field that you specify. To add or remove rules from a rule set, perform one or more of the following steps:

  • Select or clear the check box of the group node to add or remove all the rules in the group. When you select a group, all rules are set to the Warning action.

  • Click the Action field of a group, and then specify the action to apply to all rules in the group.

  • Select or clear the check box for an individual rule. When you select the check box for a rule, the rule is set to the Warning action.

You can use the toolbar of the rule set editor to group, filter, and search the data that appears in the rule set grid.

The following table describes the controls on the toolbar of the rule set editor.

Toolbar controlDescription
Expand AllShows the rules in all groups.
Collapse AllHides the rules in all groups.
Group BySpecifies the field by which rules are grouped. Click <None> to show the rules without groups.
Column OptionsSpecifies the rule fields to display.
Hide rules that do not apply to the current solutionShows or hides rules that are not of the same Target Type as the solution.
Show rules that can generate Code Analysis errorsShows or hides rules that are assigned the Error action.
Show rules that can generate Code Analysis warningsShows or hides rules that are assigned the Warning action.
Show rules that are not enabledShows or hides rules that are assigned the None action.
Add or remove child rule setsAdds or removes the rules in the selected rule sets.
Search rulesSearches all field values for the string that you specify.

Rule set fields display information about a rule set and can be used to sort and group the rule list. To display or hide fields, click Column Options on the rule set editor toolbar, and then check or clear the check boxes of the fields to show or hide.

The following table describes fields of a rule set.

FieldDescription
IDThe identifier of the rule.
CategoryIn addition to their membership in rule sets, code analysis rules are also grouped by category. For more information, see Code Analysis for Managed Code Warnings.
NameThe title of the rule.
NamespaceThe namespace of the rule.
Target TypeIndicates whether the rule is for native, managed, or database code.
ActionThe action taken when the rule is violated in a code analysis run.

 Warning - generates a warning.

 Error - generates an error.

 None - disables the rule.

You can edit the Action field. Setting the value to None is the same as clearing the check box for the rule.
Source Rule SetsThe rule set that contains the rule.

From the column headers of the rule set grid, you can sort and filter the rules by the values of the field.

  • To sort the rule set lists, click the column header of the field by which you want to sort. If the rule sets are grouped, each group is sorted individually.

  • To filter the rule sets by the value of a field, click the filter button on the column header of the field by which you want to filter. Select the check boxes of the values that you want to show, and clear the check boxes of the values that you want to hide.

Show: