Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Help To Use EnvDTE - A Little Simple Library

0.00/5 (No votes)
24 Apr 2007 1  
A piece of library that can help to use Visual Studio Editor to search, write, change code directly in the code
Screenshot - screenshot.jpg

Introduction

This article shows you how to get control of the currently running Visual Studio IDE instance. You can get a reference to the DTE object - the top-level object in the Visual Studio automation object model. Once you have a reference to this object, you can query for information about a solution, projects in a solution, start builds, etc.

My code is a very simple library, the point is to demonstrate it using the DTE object. For more detailed automation examples, you can look at the MSDN documentation, but this article should help you get started with a reference to the object model.

The DTE Object

DTE stands for "Development Tools Extensibility" and is the object's codeclass. It implements the interface "_DTE". You can find more information about the DTE object in the Visual Studio documentation under "DTE object", and in the document "Referencing the DTE object".

Using the Code

The file library contains a class VisualStudioIdea which defines a few of the relevant methods. The first thing we need is to be able to get at the system's Running Object Table. To do this, we'll need access to a couple of functions that live in ole32.dll:

[DllImport("ole32.dll", EntryPoint = "GetRunningObjectTable")]
static extern uint GetRunningObjectTable(uint res, out UCOMIRunningObjectTable ROT);
[DllImport("ole32.dll", EntryPoint = "CreateBindCtx")]
static extern uint CreateBindCtx(uint res, out UCOMIBindCtx ctx);

Now you are able to use Connect:

public static bool Connect()

public static Project GetCurrentProject() 
more...
public static bool Disconnect()

History

This is a first raw version of this library born around March 2007.

About Elia Conchione

Elia Conchione is a software engineer living in Lugano, CH. Current programming interests include C, C++, C#, Linux, Unix, Mac OS X, Safe Code, encryption applications.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here