共用方式為


Can Addins & managed packages live together?; Getting to the DTE object model from a package

Addins & Packages - can they talk to each other?

I recently received a question on this from a VSIP partner (Velocitis) so I thought I'd share the info with everyone.

Getting to a package from an addin is fairly straightforward. The package can expose a globally accessible service (managed packages can use the ProvideService attribute of the VSIP Extras Helper classes). The addin can then QI the DTE object for IServiceProvider. The returned IServiceProvider.QueryService method can be used to access the package's service interface. Managed code simply casts the DTE to IServiceProvider and then calls the QueryService method. Once the addin has the service interface for the package, the addin & package can work together all they want.

Getting to the DTE object model from a managed VSIP package

(I thought I blogged this previously, but I can't find it now. Sorry if this is a repeat...)

Getting to DTE from a managed package is simple. Here's how you do it:

  1. In your managed package project, you add a reference to EnvDTE.dll.
  2. Then you write code that looks like this:

using EnvDTE;
class Foo
{
public SomeMethod()
{
DTE theDTE = (DTE) GetService(typeof(DTE));
}
}

Getting to DTE from a native package is covered in a recent Dr. eX blog entry.

I hope this helps.

Comments