繼續從MS的this教程,我已經創建了一個Roslyn分析器。Roslyn分析儀規則不會失敗的版本
根據頁面,您可以標記該規則爲DiagnosticSeverity.Error
,而這將導致構建打破:
In the line declaring the Rule field, you can also update the severity of the diagnostics you’ll be producing to be errors rather than warnings. If the regex string doesn’t parse, the Match method will definitely throw an exception at run time, and you should block the build as you would for a C# compiler error. Change the rule’s severity to DiagnosticSeverity.Error:
internal static DiagnosticDescriptor Rule = new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, Category, DiagnosticSeverity.Error, isEnabledByDefault: true, description: Description);
在我的代碼,我已經創建的規則或多或少這裏詳細:
private static readonly DiagnosticDescriptor Rule =
new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, Category,
DiagnosticSeverity.Error, true, helpLinkUri: HelpUrl);
此規則正常工作。它拋出紅線,它顯示錯誤列表中的消息。但是,構建成功,並且我能夠成功運行該應用程序。
注意:我創建了這個規則來捕獲Thread.Sleep
這個例子。
有保證的規則打破了構建需要額外的設置嗎?