是否有一个选项可以在不创建“GlobalSuppressions.cs”文件的情况下停用样式警察规则

我们在项目中使用 StyleCop 分析器。我的任务之一是停用一些规则,但不创建GlobalSuppressions.cs文件。

我找到了解决方案,但仅限于创建此文件,所以我很困惑。


智慧大石
浏览 81回答 1
1回答

翻阅古今

要抑制 之外的警告GlobalSuppressions.cs,您可以:使用注释(记得恢复超出范围的警告!)#pragma warning disable IDE0052 // Remove unread private membersprivate 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>
打开App,查看更多内容
随时随地看视频慕课网APP