Skip to content

Commit 40caeba

Browse files
committed
clarify section on suppressing from error list
1 parent 6c708fc commit 40caeba

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

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

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -102,42 +102,42 @@ You can change the severity of a rule from **Solution Explorer**, or within the
102102

103103
There are multiple ways to suppress rule violations:
104104

105-
- To suppress all current violations, select **Analyze** > **Run Code Analysis and Suppress Active Issues** on the menu bar. This is sometimes referred to as "baselining".
105+
- From the **Analyze** menu.
106106

107-
- To suppress a diagnostic from **Solution Explorer**, set its severity to **None**.
107+
Select **Analyze** > **Run Code Analysis and Suppress Active Issues** on the menu bar to suppress all current violations. This is sometimes referred to as "baselining".
108108

109-
- To suppress a diagnostic from the rule set editor, uncheck the box next to its name, or set **Action** to **None**.
109+
- From **Solution Explorer**
110110

111-
- To suppress a diagnostic from the code editor, place the cursor in the line of code with the violation and press **Ctrl**+**.** to open the **Quick Actions** menu. Select **Suppress CAxxxx** > **In Source** or **Suppress CAxxxx** > **In Suppression File**.
111+
To suppress a violation in **Solution Explorer**, set the rule's severity to **None**.
112112

113-
![Suppress diagnostic from quick actions menu](media/suppress-diagnostic-from-editor.png)
113+
- From the **rule set editor**
114+
115+
To suppress a violation from the rule set editor, uncheck the box next to its name or set **Action** to **None**.
114116

115-
- To suppress a diagnostic from the **Error List**, see [Suppress violations from the Error List](#suppress-violations-from-the-error-list).
117+
- From the **code editor**
116118

117-
### Suppress violations from the Error List
119+
To suppress a violation from the code editor, place the cursor in the line of code with the violation and press **Ctrl**+**.** to open the **Quick Actions** menu. Select **Suppress CAxxxx** > **In Source/In Suppression File**.
118120

119-
You can suppress one or many diagnostics from the **Error List** by selecting the ones you want to suppress, and then right-clicking and selecting **Suppress** > **In Source** or **Suppress** > **In Suppression File**.
121+
![Suppress diagnostic from quick actions menu](media/suppress-diagnostic-from-editor.png)
120122

121-
- If you select **In Source**, the **Preview Changes** dialog opens and shows a preview of the C# [#pragma warning](/dotnet/csharp/language-reference/preprocessor-directives/preprocessor-pragma-warning) or Visual Basic [#Disable warning](/dotnet/visual-basic/language-reference/directives/directives) directive that's added to the source code.
123+
- From the **Error List**
122124

123-
![Preview of adding #pragma warning in code file](media/pragma-warning-preview.png)
125+
You can suppress one or many diagnostics from the **Error List** by selecting the ones you want to suppress, and then right-clicking and selecting **Suppress** > **In Source/In Suppression File**.
124126

125-
- If you select **In Suppression File**, the **Preview Changes** dialog opens and shows a preview of the <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute> attribute that's added to the global suppressions file.
127+
- If you supress **In Source**, the **Preview Changes** dialog opens and shows a preview of the C# [#pragma warning](/dotnet/csharp/language-reference/preprocessor-directives/preprocessor-pragma-warning) or Visual Basic [#Disable warning](/dotnet/visual-basic/language-reference/directives/directives) directive that's added to the source code.
126128

127-
![Preview of adding SuppressMessage attribute to suppression file](media/preview-changes-in-suppression-file.png)
129+
![Preview of adding #pragma warning in code file](media/pragma-warning-preview.png)
128130

129-
In the **Preview Changes** dialog, select **Apply**.
131+
- If you select **In Suppression File**, the **Preview Changes** dialog opens and shows a preview of the <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute> attribute that's added to the global suppressions file.
130132

131-
The **Error List** displays diagnostics, or rule violations, from both live code analysis and build. Since the build diagnostics can be stale, for example, if you've edited the code to fix the violation but haven't rebuilt, you cannot suppress these diagnostics from the **Error List**. However, diagnostics from live analysis, or IntelliSense, are always up-to-date with current sources, and can be suppressed from the **Error List**. If the suppression option is disabled in the right-click, or context, menu, it's likely because you have one or more build diagnostics in your selection. To exclude the build diagnostics from your selection, switch the **Error List** source filter from **Build + IntelliSense** to **Intellisense Only**. Then, select the diagnostics you want to suppress and proceed as described previously.
133+
![Preview of adding SuppressMessage attribute to suppression file](media/preview-changes-in-suppression-file.png)
132134

133-
![Error List source filter in Visual Studio](media/error-list-filter.png)
135+
In the **Preview Changes** dialog, select **Apply**.
134136

135-
> [!NOTE]
136-
> In a .NET Core project, if you add a reference to a project that has NuGet analyzers, those analyzers are automatically added to the dependent project too. To disable this behavior, for example if the dependent project is a unit test project, mark the NuGet package as private in the *.csproj* or *.vbproj* file of the referenced project:
137-
>
138-
> ```xml
139-
> <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.6.0" PrivateAssets="all" />
140-
> ```
137+
> [!NOTE]
138+
> If you don't see the **Suppress** menu option in **Solution Explorer**, the violation is likely coming from build and not live analysis. The **Error List** displays diagnostics, or rule violations, from both live code analysis and build. Since the build diagnostics can be stale, for example, if you've edited the code to fix the violation but haven't rebuilt, you cannot suppress these diagnostics from the **Error List**. Diagnostics from live analysis, or IntelliSense, are always up-to-date with current sources and can be suppressed from the **Error List**. To exclude *build* diagnostics from your selection, switch the **Error List** source filter from **Build + IntelliSense** to **Intellisense Only**. Then, select the diagnostics you want to suppress and proceed as described previously.
139+
>
140+
> ![Error List source filter in Visual Studio](media/error-list-filter.png)
141141
142142
## Command-line usage
143143

@@ -164,6 +164,14 @@ The following image shows the command-line build output from building a project
164164

165165
![MSBuild output with rule violation](media/command-line-build-analyzers.png)
166166

167+
## Dependent projects
168+
169+
In a .NET Core project, if you add a reference to a project that has NuGet analyzers, those analyzers are automatically added to the dependent project too. To disable this behavior, for example if the dependent project is a unit test project, mark the NuGet package as private in the *.csproj* or *.vbproj* file of the referenced project by setting the **PrivateAssets** attribute:
170+
171+
```xml
172+
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.0" PrivateAssets="all" />
173+
```
174+
167175
## See also
168176

169177
- [Overview of Roslyn analyzers in Visual Studio](../code-quality/roslyn-analyzers-overview.md)

0 commit comments

Comments
 (0)