显示带有源文件/行的构建时工具中的错误 [英] Showing errors from a build-time tool with source file/line

查看:46
本文介绍了显示带有源文件/行的构建时工具中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目有一个MSBuild目标,该目标运行一个生成一些文件的工具:

My project has an MSBuild target which runs a tool which generated some files:

<Exec Command="$(MyTool) @(Content)"
      ConsoleToMSBuild="true"
      IgnoreExitCode="False"
      LogStandardErrorAsError="true" />

如果该工具在其输入(@(Content)文件)中检测到某些错误,则将错误输出为标准错误.这使MSBuild无法生成,而Visual Studio则在错误列表中显示此文本-所有这些都很棒!

If the tool detects some error in its inputs (the @(Content) files), it outputs the error to standard error. This makes MSBuild to fail the build, and Visual Studio to show this text in the error list - all of which is great!

现在,该工具还知道错误所在的确切文件和行,并且我希望错误列表显示该错误,并且双击将导致该文件.如果该工具是MSBuild Task而不是独立exe,则可以调用 .如何使用独立的exe工具来完成相同的工作?我是否需要编写一个包装器任务来分析工具的错误?已经有这样的任务了吗?

Now, the tool also knows the exact file&line where the error is, and I want the error list to show that, and that double-click would lead to the file. If the tool were an MSBuild Task rather than a standalone exe, I could call TaskLoggingHelper.LogError(..., file, lineNumber, ...). How can I accomplish the same with a standalone exe tools? Do I need to write a wrapper task which parses the tool's error? Is there such a task already available?

推荐答案

我不知道有任何现成的机制可以做到这一点,但请参见例如在Visual Studio中查看PowerShell的Select-String输出:所有您需要做的就是使您的输出与VS期望的相匹配,并且您会自动获得期望的行为. VS查找类似

I don't know of any readily available mechanism to do this but see e.g. Viewing PowerShell's Select-String output in Visual Studio: al you need to do is make your output match what VS expects and you automatically get desired behaviour. VS looks for messages like

<file>(<line>): error <code>: <message>

例如,msbuild,编译器,链接器消息均遵循此格式.因此,如果您具有自定义工具输出的格式,则它将显示在错误列表"中,您可以双击它以导航到指定的文件和行.

For instance msbuild, compiler, linker messages all adhere to this format. So if you have your custom tool output that format it will be shown in the Error List and you can doubleclick on it to navigate to the specified file and line.

这篇关于显示带有源文件/行的构建时工具中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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