我们在项目中使用StyleCop Analyzer。我的任务之一是停用一些规则,但不创建GlobalSuppressions.cs
文件。
我找到了解决方案,但只能创建此文件,所以我很困惑。
答案 0 :(得分:1)
要禁止显示GlobalSuppressions.cs
以外的警告,您可以:
使用注释(请记住将警告还原到范围之外!)
#pragma warning disable IDE0052 // Remove unread private members
private readonly Object _obj;
#pragma warning restore IDE0052 // Remove unread private members
或就地使用SuppressMessage
属性
[SuppressMessage("Code Quality", "IDE0052:Remove unread private members", Justification = "<Pending>")]
private readonly Object _obj;
如果要全局禁用它们,还可以配置规则集文件。
在您的csproj中:
<PropertyGroup>
<CodeAnalysisRuleSet>File.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
,然后根据需要创建File.ruleset
。看起来很像
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Microsoft Managed Recommended Rules" Description="These rules focus on the most critical problems in your code, including potential security holes, application crashes, and other important logic and design errors. It is recommended to include this rule set in any custom rule set you create for your projects." ToolsVersion="10.0">
<Rules AnalyzerId="Microsoft.CodeQuality.Analyzers" RuleNamespace="Microsoft.CodeQuality.Analyzers">
<Rule Id="CA1056" Action="None" />
</Rules>
</Rules>
</RuleSet>