Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to acquire DTE object instance in a VS package project?

How can I get DTE instance in a VS package project? It's straigtforward in addin project since application is being passed as an argument to onConnection method, but it is unclear how to get it in a package.

like image 217
Violet Giraffe Avatar asked Sep 13 '25 15:09

Violet Giraffe


2 Answers

From your main Package class:

EnvDTE80.DTE2 dte = this.GetService(typeof(Microsoft.VisualStudio.Shell.Interop.SDTE)) as EnvDTE80.DTE2;
like image 51
Sergey Vlasov Avatar answered Sep 16 '25 06:09

Sergey Vlasov


You can get a null instance getting the SDTE service if the shell is not fully initialized. See how to handle that in this code sample:

HOWTO: Get the EnvDTE.DTE instance from a package

like image 27
Carlos Quintero Avatar answered Sep 16 '25 06:09

Carlos Quintero