I am writing a custom tool and I currently have it doing what I want as far as functionality. I would like to be able to write to Visual Studio if something goes wrong. (Incorrectly formatted code or whatever).
Are there any standards for this? Right now I basically can force the tool to fail and Visual Studio puts in a warning that it has done so. I'd like a category in the Output window with any resulting messages I want to send. I could also live with a more descriptive task/warning in the Error list window.
Output Window
To write to the "General" output window in Visual Studio, you need to do the following:
If, however, you want to write to a custom window, this is what you need to do:
Details on IVsOutputWindow and IVsOutputWindowPane can be found on MSDN.
Error List
For adding items to the error list, the
IVsSingleFileGenerator
has a method callvoid Generate(...)
which has a parameter of the typeIVsGeneratorProgress
. This interface has a methodvoid GeneratorError()
which lets you report errors and warnings to the Visual Studio error list.The details of GeneratorError() can be found on MSDN.
There is another way using
Marshal.GetActiveObject
to grab a runningDTE2
instance.First reference EnvDTE and envdte80. This currently works in VisualStudio 2012, I haven't tried the others yet.
If you want anything to appear in the Output window, it has to come from stdout. To do this, your app needs to be linked as a "console" app. Set the /SUBSYSTEM:CONSOLE flag in the project's property page, under Linker/System set the SubSystem property to CONSOLE.
Once you have your output in the window, if you include the text "Error:" it will appear as an error, or if you set "Warning:" it will appear as a warning. If your error text begins with a path/filename, followed by a line number in parenthesis, the IDE will recognize it as a "clickable" error, and navigate you automatically to the faulting line.
use
System.Diagnostics.Debugger.Message
You can use the Debug and/or Trace classes. There is some information here: http://msdn.microsoft.com/en-us/library/bs4c1wda(VS.71).aspx
Best of luck.