Search code examples
visual-studiohookvisual-studio-extensionsvisual-studio-addinsvsix

Visual Studio Extension: how to intercept / modify / delete build Error Messages in the Error List?


I'm working on a Visual Studio extension that will "clean up" compilation error messages to make them easier to read.

I already know how to generate my own errors. Instead, what I am trying to do is modify/replace the text of the error messages that Visual Studio adds to the Error List pane as a result of parsing compilation output.

So far I have been unsuccessful in finding a way to do this. Here are my findings:

  • The IVsTaskItems in the SVsErrorList are all read-only, so I cannot edit them directly.
  • I cannot delete the IVsTaskItems either, for the same reason (and hence cannot replace them with my own).
  • I can append my own text to the Build Output Window pane, but I am not able to modify the existing text in order edit the error messages before Visual Studio parses them.

Is there some other way to accomplish this goal? Is there, within an extension, a way to:

  • to hook the call that VS makes internally to add an error message to the Error List, and change it before it is processed?
  • to hook the output from the build process and modify it before it is processed by VS?
  • to accomplish this via some other means?

Solution

  • The proper way of doing this would be to either modify the output of your compilation process, or modify the way your project system and/or .targets file reports the information from the compiler to the IDE. If you don't have control over either the compiler or the project system, then this would be a difficult to impossible task.

    1. Displayed tasks implement IVsTaskItem, and this interface is actually implemented by client code so there are no guarantees that a task item will provide the ability to modify any of its values.

    2. The IVsTaskList2 interface adds a method RemoveTasks, but it requires you have the provider cookie that was returned when the provider was registered (and there is no way to get this).