继续从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
这个例子。
有保证的规则打破了构建需要额外的设置吗?