Roslyn – custom build error extension
Just like Slaks and JoshVarty said, this is an analyzer feature. To create your custom Roslyn analyzer rule, you can check this MS tutorial:
C# and Visual Basic - Use Roslyn to Write a Live Code Analyzer for Your API.
In this document, you can find following description:
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);
This will cause the build to break.
And
In order to make the build fail for the rules, you need to add the
analyzer as a nuget package to the project. This will ensure that
failures will cause the build to fail as expected.
Certification:Roslyn Analyzer Rule does not fail the build.
Hope this helps.