尽管 Roslyn 诊断分析器存在一些错误,但编译成功 [英] Compilation succeeded even though there were some errors from Roslyn Diagnostic Analyzer

查看:49
本文介绍了尽管 Roslyn 诊断分析器存在一些错误,但编译成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DiagnosticAnalyzer 是一个基于 Roslyn 的自定义扩展,其 DiagnosticDescriptorDiagnosticSeverity.Error 如下所示

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);

使用扩展程序时,它确实会显示代码上的红色波浪线,这违反了诊断分析器自定义规则,强调这是一个错误strong>,它甚至会显示在 Visual Studio 的错误列表窗口中.

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.

但是在编译时,此代码在 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.

如果这是 Roslyn 的默认工作方式,那么我们是否有解决方法来停止编译.

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

我正在使用:

  1. Visual Studio 2013 更新 3
  2. Roslyn 最终用户预览版.vsix
  3. 包含使用 Roslyn SDK 项目模板制作的 DiagnosticAnalyzer 的 VSIX 扩展.vsix

推荐答案

将诊断集成到实际构建管道中是 VS14"的一部分.如果您在那里尝试相同的场景,则会导致编译错误.

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.

此外,诊断现在附加到项目并通过 NuGet 分发,以便整个团队、持续集成构建等都始终如一地发生错误.

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.

这篇关于尽管 Roslyn 诊断分析器存在一些错误,但编译成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆