MSからのthisチュートリアルの後、私はRoslyn用のアナライザを作成しました。Roslyn Analyzerルールがビルドに失敗しない
ページによると、あなたは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);
このルールは正常に機能します。それは赤い線を投げ、エラーリストにメッセージを表示します。しかし、ビルドは成功し、アプリケーションを正常に実行することができます。
NB:この例ではThread.Sleep
をキャプチャするためにこのルールを作成しました。