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

走远了吗. 提交于 2019-12-23 00:43:26

问题


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

回答1:


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.




回答2:


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)



来源:https://stackoverflow.com/questions/26113987/compilation-succeeded-even-though-there-were-some-errors-from-roslyn-diagnostic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!