Roslyn:如何修复 RS2008 警告?
Posted
技术标签:
【中文标题】Roslyn:如何修复 RS2008 警告?【英文标题】:Roslyn: How to fix RS2008 warning? 【发布时间】:2021-12-07 20:22:34 【问题描述】:这里也有人问这个问题:https://github.com/dotnet/roslyn/issues/57292
在 Roslyn 3.8.0 中,以下代码出现 RS2008 警告(为包含规则“EO0001”的分析器项目启用分析器发布跟踪):
internal static class Rules
public static readonly DiagnosticDescriptor InvalidFieldAttribute = new DiagnosticDescriptor(
DiagnosticIds.InvalidFieldAttribute,
new LocalizableResourceString(nameof(Resources.InvalidFieldAttribute_Title), Resources.ResourceManager, typeof(Resources)),
new LocalizableResourceString(nameof(Resources.InvalidFieldAttribute_Message), Resources.ResourceManager, typeof(Resources)),
DiagnosticCategories.Usage, DiagnosticSeverity.Warning, isEnabledByDefault: true);
按CTRL-.
添加以下两个文件快速修复:
AnalyzerReleases.Shipped.md
:
; Shipped analyzer releases
; https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md
## Release 1.0
### New Rules
Rule ID | Category | Severity | Notes
--------|----------|----------|--------------------
OE0001 | Usage | Warning | InvalidFieldAttribute
AnalyzerReleases.Unshipped.md
:
; Unshipped analyzer release
; https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md
但是 RS2008 警告仍然存在。
我错过了什么?
【问题讨论】:
【参考方案1】:通过在项目文件中添加AdditionalFiles
从https://github.com/dotnet/roslyn/issues/57292 得到答案:
<ItemGroup>
<AdditionalFiles Include="AnalyzerReleases.Shipped.md" />
<AdditionalFiles Include="AnalyzerReleases.Unshipped.md" />
</ItemGroup>
【讨论】:
以上是关于Roslyn:如何修复 RS2008 警告?的主要内容,如果未能解决你的问题,请参考以下文章