
386
|
Chapter 12, Extending Visual Studio
#87 Access Visual Studio from Standalone Applications
HACK
HACK
#87
Access Visual Studio from Standalone
Applications Hack #87
When a macro or add-in is not what you are looking for, you can always use
the automation object model from a normal Windows Forms application.
The EnvDTE assembly can be referenced by C# and VB.NET applications to
directly reference the Visual Studio IDE. Using this assembly, you can mod-
ify windows, add custom toolbox items, and much more. Working with this
assembly has a number of pitfalls though, and this hack shows ways to get
around them.
When using the DTE object from an application. you can perform any of the
same actions that you would normally do from a macro or add-in.
You can get a reference to the currently executing instance of
Visual Studio using this line of code:
EnvDTE.DTE dte =
(DTE)Marshal.GetActiveObject("VisualStudio.DTE.
7.1");
This will return a reference to the currently executing
instance of Visual Studio as opposed to a reference to a new
instance of Visual Studio.
Version Issues
After adding a reference to the EnvDTE assembly in your project, the first
thing you normally will do is create an instance of the DTE object, using a
line of code like this:
DTE env = new DTE( );
This will work fine if you have only Visual Studio .NET 2002 installed. If
you also have another version of Visual Studio installed, then no