1 回答

TA貢獻1780條經驗 獲得超5個贊
要抑制 之外的警告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;
如果您想全局禁用它們,可以在解決方案的根目錄下使用.editorconfig文件。
root = true
[*.{cs,vb}]
dotnet_diagnostic.IDE0052.severity = none
您還可以配置規則集文件,但現已棄用。
在您的 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>
- 1 回答
- 0 關注
- 122 瀏覽
添加回答
舉報