问题
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).
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.
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();
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).
回答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();
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).
来源:https://stackoverflow.com/questions/23322295/writing-to-output-build-pane-error-list-in-visual-studio-2013-with-ability-to