![]() |
||||
|
This article describes how to automate the Visual Studio .NET IDE from outside the IDE. More Information Visual Studio .NET exposes an extensibility model that can be used to automate it. This object model resides in the EnvDTE.dll assembly, which you can explore using the Object Browser. The root class of the object model is EnvDTE.DTE, and therefore you need an instance of this class to automate it. You have the following ways to automate the Visual Studio .NET IDE:
The previous methods automate the IDE from within, but there is a third method that you can use to automate the IDE from the outside, for example from other application or from a script. To do this, first you need to create an instance of the EnvDTE.DTE class. This is done using the CreateObject function of most COM-aware languages, passing the ProgID of the class. The list of available ProgIDs is the following:
There are two important properties that control the behavior of the IDE while you are automating it from the outside:
The following VBScript sample shows how to create an instance of Visual Studio .NET 2003 and show its name and version: Dim objDTE
' Creates an instance of the Visual Studio .NET 2003 IDE
Set objDTE = CreateObject("VisualStudio.DTE.7.1")
' While the instance is still invisible, show its name and version
MsgBox objDTE.Name & " " & objDTE.Version
' Make it visible and keep it open after we finish this script
objDTE.MainWindow.Visible = True
objDTE.UserControl = True
The following VB.NET sample does the same: Dim objType As Type
Dim objDTE As EnvDTE.DTE
' Creates an instance of the Visual Studio .NET 2003 IDE
objType = Type.GetTypeFromProgID("VisualStudio.DTE.7.1")
objDTE = DirectCast(System.Activator.CreateInstance(objType), EnvDTE.DTE)
' While the instance is still invisible, show its name and version
MsgBox objDTE.Name & " " & objDTE.Version
' Make it visible and keep it open after we finish this script
objDTE.MainWindow.Visible = True
objDTE.UserControl = True
Go back to the 'Resources for Visual Studio .NET extensibility' section for more articles like this
You can code, design, locate code and document your apps much faster using VB.NET, C#, C++ or Visual J#:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||