在Visual Studio 2013中写入输出生成窗格+错误列表,无需双击即可使用msbuild/new进程双击条目以出错 [英] Writing to output build pane + error list in Visual Studio 2013 with ability to double click entry to go to error without using msbuild/new process

本文介绍了在Visual Studio 2013中写入输出生成窗格+错误列表,无需双击即可使用msbuild/new进程双击条目以出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是自定义生成工具,我从正在创建的Visual Studio 2013扩展包中以dll的形式调用它,我想从此工具返回的字符串输出进行解析,以获取错误,行数字等,然后将其输出到构建窗格+错误列表,并具有双击错误所在文件的源位置的功能.

I'm using a custom build tool which I call as a dll from within a Visual Studio 2013 extension package I'm creating and I would like to take the string output returned from this tool, parse it for the error, line number etc. and output it to the build pane + error list complete with the ability to double click to go to the source location in the file with the error.

当前,我可以将信息输出到窗格和错误列表,但是双击源功能在输出列表或错误列表中均不起作用(在输出窗口中单击字符串时,其作用类似于普通文本在文本文件中).

Currently I can output the information to the pane and error list but the double click to go to source functionality does not work either in the output or error list (when clicking on the string in the output window it just acts like normal text in a text file).

以下代码是我尝试使用OutputTaskItemString将测试错误写入构建窗格/错误列表的尝试.我相信该字符串的格式正确,可用于Visual Studio解析,以使错误感知"功能正常工作.

The code below is my attempt to write a test error to the build pane/error list using OutputTaskItemString. I believe that the string is formatted correctly for visual studio to parse for the "error aware" functionality to work.

如果我将我的工具作为外部进程运行到stdout,则输出到窗格的效果很好,但错误列表中没有任何内容.

If I run my tool as an external process printing to stdout then the output to pane works fine but I don't get anything in the error list.

       var outputWindow = GetService(
            typeof(SVsOutputWindow)) as IVsOutputWindow;
        IVsOutputWindowPane pane;
        Guid guidGeneralPane =
            VSConstants.GUID_BuildOutputWindowPane;
        outputWindow.GetPane(ref guidGeneralPane, out pane);

        pane.Activate();

        pane.OutputTaskItemString("I:\\LLVM_BUILD\\VC12\\64\\Release\\bin\\test.cpp(12,2) :  error: void function 'functionTest' should not return a value [-Wreturn-type] return 0;", VSTASKPRIORITY.TP_HIGH, VSTASKCATEGORY.CAT_BUILDCOMPILE,
            "Error", (int)Microsoft.VisualStudio.Shell.Interop._vstaskbitmap.BMP_COMPILE, "I:\\LLVM_BUILD\\VC12\\64\\Release\\bin\\test.cpp", 12, "error: void function 'functionTest' should not return a value [-Wreturn-type] return 0");

        pane.FlushToTaskList();

关于此主题还有其他问题,但是没有一个问题可以解决我要尝试做的事情(没有msbuild或触发外部进程的错误感知"构建输出).

There are other questions about this topic but none of them gave a solution for what I'm trying to do specifically ("error aware" build output without msbuild or triggering an external process).

推荐答案

原来,我所需要的只是输出字符串中的换行符.还请注意,错误行是基于0的数组,因此0 =第1行.

Turns out all I needed was a newline in the output string. Also note that error line is a 0 based array so 0 = line 1.

            pane.OutputTaskItemString("I:\\LLVM_BUILD\\VC12\\64\\Release\\bin\\test.cpp(12,2) :  error: void function 'functionTest' should not return a value [-Wreturn-type]\n return 0;\n", VSTASKPRIORITY.TP_HIGH, VSTASKCATEGORY.CAT_BUILDCOMPILE,
            "Error", (int)Microsoft.VisualStudio.Shell.Interop._vstaskbitmap.BMP_COMPILE, "I:\\LLVM_BUILD\\VC12\\64\\Release\\bin\\test.cpp", 11, "error: void function 'functionTest' should not return a value [-Wreturn-type] return 0");

        pane.FlushToTaskList();

通过此操作,您应该在输出窗格&中获得可点击的错误.错误列表(显然,您需要自己解析每个OutputTaskItemString的错误信息).

With this you should get the clickable error in output pane & error list (obviously you need to parse the error info for each call to OutputTaskItemString yourself).

这篇关于在Visual Studio 2013中写入输出生成窗格+错误列表,无需双击即可使用msbuild/new进程双击条目以出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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