要抑制 之外的警告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>