http://blogs.clariusconsulting.net/pga

Pablo Galiano's Blog

Go Back to
pga′s Latest post

How to open files from the Output window

My seventeenth How do I is up.

Scenario

The Visual Studio output window supports file opening. When we write to the output window a string with a specific mask, we can use the navigation buttons or double click the line and Visual Studio will open the file and position the caret in the corresponding line an column.


out.png

 

Interfaces and classes needed


 

Code snippet

    IServiceProvider serviceProvider = this;

 

    IVsOutputWindow outputwindow =

        serviceProvider.GetService(typeof(SVsOutputWindow)) asIVsOutputWindow;

    Guid generalGuidPane = VSConstants.GUID_OutWindowGeneralPane;

    IVsOutputWindowPane generalPane;

    ErrorHandler.ThrowOnFailure(outputwindow.GetPane(ref generalGuidPane, out generalPane));

 

    //MASK:

    //FilePath(#Line,#Column) : MessageToDisplay

 

    //Ex:

    //D:\Work\Temp\VSPackage4\VSPackage4\VSPackage4Package.cs(83,79) : Foo

 

    generalPane.OutputStringThreadSafe(

        string.Concat(

            @”D:\Work\Temp\VSPackage4\VSPackage4\VSPackage4Package.cs(83,79) : Foo”,

            Environment.NewLine));

 

    ErrorHandler.ThrowOnFailure(generalPane.FlushToTaskList());


Assemblies needed

  • Microsoft.VisualStudio.Shell.Interop, Version=7.1.40304.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

 

Stay tuned,

Pablo

Comments