Theo sau từ this hướng dẫn từ MS, tôi đã tạo một trình phân tích cho Roslyn.Quy tắc phân tích Roslyn không thất bại trong việc xây dựng
Theo trang, bạn có thể đánh dấu sự cai trị như DiagnosticSeverity.Error
, và điều này sẽ gây ra xây dựng để phá vỡ:
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);
Trong mã của tôi, tôi đã tạo ra sự cai trị nhiều hơn hoặc ít hơn như trình bày chi tiết ở đây:
private static readonly DiagnosticDescriptor Rule =
new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, Category,
DiagnosticSeverity.Error, true, helpLinkUri: HelpUrl);
Quy tắc này hoạt động tốt. Nó ném lên các đường màu đỏ, nó hiển thị thông báo trong danh sách lỗi. Tuy nhiên, việc xây dựng thành công và tôi có thể chạy ứng dụng thành công.
NB: Tôi đã tạo quy tắc này để chụp Thread.Sleep
cho ví dụ này.
Có thiết lập bổ sung cần thiết để đảm bảo một quy tắc phá vỡ xây dựng?