简体   繁体   中英

Compilation succeeded even though there were some errors from Roslyn Diagnostic Analyzer

The DiagnosticAnalyzer is a custom Roslyn based extension whose DiagnosticDescriptor with DiagnosticSeverity.Error is as shown below

internal static DiagnosticDescriptor Rule = new DiagnosticDescriptor(DiagnosticId, Description, MessageFormat, Category, DiagnosticSeverity.Error);

When the extension is used it does show the red squiggles over the codes that is against the Diagnostic Analyzers custom rule emphasising that it is an error , it is even shown in the Error List window of Visual Studio.

But when compiled , this code gets a compilation succeeded message in the Output Window of Visual Studio. This is working against the whole concept of emphasising an error as severity for a diagnostic analyzer.

错误编译成功

If this is the default way of working for Roslyn, then do we have a work around for stopping the compilation .

I'm using:

  1. Visual Studio 2013 Update 3
  2. Roslyn End User Preview.vsix
  3. VSIX extension containing the DiagnosticAnalyzer made using Roslyn SDK Project Templates.vsix

The integration of diagnostics into the actual build pipeline has been happening as part of VS "14". If you try the same scenario there, it will cause a compilation error.

Additionally, diagnostics are now attached to projects and distributed via NuGet so that the errors will happen consistently for the entire team, continuous integration build, etc.

I'm using VS2015 Update 3 and this issue is still there. I wanted to enforce local variable and parameter naming conventions, it turned out Roslyn doesn't support these by default, only by workaround: SO link

Then I wanted to fail the build if there is such an error, but Roslyn is not capable of this.

Roslyn could have been a very robust and powerful tool, but it is still failing in the most basic tasks. What a pity.

(For the moderators: I still don't have 50 rep to comment and I don't think I will ever have)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM