4

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

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

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!

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?

Jonathan
  • 6,939
  • 4
  • 44
  • 61

1 Answers1

7

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>

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.

Community
  • 1
  • 1
stijn
  • 34,664
  • 13
  • 111
  • 163
  • Holy answer from holy stijn! With high experience in Microsoft's environment, it is pity that you didn't advertise any of your books (if any) in your profile page. – javaLover Mar 30 '17 at 07:44
  • @javaLover thanks for the flowers :P unfortunately for you pretty much everything is in my head and put to use in projects which I can't publish. I do try to answer a ot of msbuild questions though to share some knowledge.. – stijn Mar 30 '17 at 12:48