Visual Studio Development Bookmark and Share   
 index > Visual Studio Guidance Automation Toolkit > Getting a handle on DTE from a library class.
 

Getting a handle on DTE from a library class.

hi guys,
i've got a library class that need to print a message to the outputwindow.. is there a way for me to get a reference to the DTE that it is running under. This library class is called from a text template action
regards.
mickdelaney  Monday, September 17, 2007 3:10 PM

You should have an IServiceProvider available in the library, if not just can also try using

DTE dte = Package.GetGlobalService(typeof(DTE)) as DTE;

You will find the Package class in the Microsoft.VisualStudio.Shell namespace

Jose Escrich  Monday, September 17, 2007 3:29 PM

You should have an IServiceProvider available in the library, if not just can also try using

DTE dte = Package.GetGlobalService(typeof(DTE)) as DTE;

You will find the Package class in the Microsoft.VisualStudio.Shell namespace

Jose Escrich  Monday, September 17, 2007 3:29 PM
cheers jose,

So i should provider an IServiceProvider in my library..... is there an example in any of the lib's out there...

regards....
mickdelaney  Monday, September 17, 2007 3:59 PM

Ok, you're calling your library from an Action so what you can do is the following...

public class MyLibrary

{

IServiceProvider serviceProvider;

public MyLibrary(IServiceProvider serviceProvider)

{

this.serviceProvider = serviceProvider;

DTE dte = (DTE) this.serviceProvider.GetService(typeof(DTE));

}

}

then in your action, you can provide that ServiceProvider through the Site property.

public override void Execute()

{

MyLibrary library = new MyLibrary(this.Site);

}

hth

jose

Jose Escrich  Monday, September 17, 2007 6:32 PM

You can use google to search for other answers

Custom Search

More Threads

• Packaging both Vb and CS in one Guidance Package
• Guidance package manager not enabled
• Trying to add a new class to the References folder...
• Error Installing to RTM Version of VS2005
• GAX - Integrated with DSL Tool
• Which APIs should be used with VSTS to do web test automation ?
• Is WSSF right for me?
• Setup missing files.
• Clarius SFT February 2007 CTP just released!!
• conditionally adding a binary reference to a project