You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/code-quality/in-source-suppression-overview.md
+18-9Lines changed: 18 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -86,6 +86,8 @@ The properties of the attribute include:
86
86
87
87
- **Target** - An identifier that is used to specify the target on which the warning is being suppressed. It must contain a fully qualified item name.
88
88
89
+
To see examples of using `SuppressMessage`, use Visual Studio to [add a suppression to the global suppression file](../code-quality/use-roslyn-analyzers.md#suppress-violations) for warnings that you see in the code editor. The suppression attribute appears in a preview window.
90
+
89
91
## SuppressMessage usage
90
92
91
93
Code Analysis warnings are suppressed at the level to which the <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute> attribute is applied. For example, the attribute can be applied at the assembly, module, type, member, or parameter level. The purpose of this is to tightly couple the suppression information to the code where the violation occurs.
@@ -141,15 +143,6 @@ public class Animal
141
143
}
142
144
```
143
145
144
-
## Generated code
145
-
146
-
Managed code compilers and some third-party tools generate code to facilitate rapid code development. Compiler-generated code that appears in source files is usually marked with the `GeneratedCodeAttribute` attribute.
147
-
148
-
You can choose whether to suppress code analysis warnings and errors for generated code. For information about how to suppress such warnings and errors, see [How to: Suppress Warnings for Generated Code](../code-quality/how-to-suppress-code-analysis-warnings-for-generated-code.md).
149
-
150
-
> [!NOTE]
151
-
> Code analysis ignores `GeneratedCodeAttribute` when it is applied to either an entire assembly or a single parameter.
152
-
153
146
## Global-level suppressions
154
147
155
148
The managed code analysis tool examines `SuppressMessage` attributes that are applied at the assembly, module, type, member, or parameter level. It also fires violations against resources and namespaces. These violations must be applied at the global level and are scoped and targeted. For example, the following message suppresses a namespace violation:
@@ -180,6 +173,22 @@ For example, the following attribute in your _GlobalSuppressions_ project file w
180
173
181
174
`[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task", Justification = "ASP.NET Core doesn't use thread context to store request context.", Scope = "module")]`
182
175
176
+
## Generated code
177
+
178
+
Managed code compilers and some third-party tools generate code to facilitate rapid code development. Compiler-generated code that appears in source files is usually marked with the `GeneratedCodeAttribute` attribute.
179
+
180
+
For source code analysis (FxCop analyzers), you can suppress messages in generated code using the [.editorconfig](../code-quality/configure-fxcop-analyzers.md) file in the root of your project or solution. Use a file pattern to match the generated code. For example, to exclude CS1591 warnings in *.designer.cs* files, use this in the configuration file.
181
+
182
+
```cmd
183
+
[*.designer.cs]
184
+
dotnet_diagnostic.CS1591.severity = none
185
+
```
186
+
187
+
For legacy code analysis, you can choose whether to suppress code analysis warnings and errors for generated code. For information about how to suppress such warnings and errors, see [How to: Suppress Warnings for Generated Code](../code-quality/how-to-suppress-code-analysis-warnings-for-generated-code.md).
188
+
189
+
> [!NOTE]
190
+
> Code analysis ignores `GeneratedCodeAttribute` when it is applied to either an entire assembly or a single parameter.
0 commit comments