我在测试方法中使用下划线以提高可读性,并且我想抑制整个测试命名空间的 FxCop 错误/警告。
我怎样才能做到这一点?我玩过 GlobalSuppressions.cs
但没有任何效果:
[module: System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores",
Scope = "namespace", Target = "Company.Product.Tests")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores",
Scope = "namespace", Target = "Company.Product.Tests")]
最佳答案
自 Visual Studio 2019 以来,可以抑制命名空间及其所有后代符号的代码分析警告:
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores",
Justification = "Test methods require underscores for readability."
Scope = "namespaceanddescendants", Target = "Company.Product.Tests")]
Scope - The target on which the warning is being suppressed. If the target is not specified, it is set to the target of the attribute. Supported scopes include the following:
...
namespaceanddescendants
- (New for Visual Studio 2019) This scope suppresses warnings in a namespace and all its descendant symbols. Thenamespaceanddescendants
value is only valid for Roslyn analyzers, and is ignored by binary, FxCop-based static analysis.
Suppress code analysis warnings#SuppressMessage attribute @ MS Docs
关于c# - 整个命名空间的“SuppressMessage”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11359652/