Click here to Skip to main content
15,867,686 members
Articles / Programming Languages / C#
Article

Help To Use EnvDTE - A Little Simple Library

Rate me:
Please Sign up or sign in to vote.
3.60/5 (36 votes)
23 Apr 2007CPOL1 min read 51K   819   24   8
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:

C#
[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:

C#
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) 42yo.com
Italy Italy
Elia Conchione is a Banking software engineer from 1986, living in Cittadella, Padova, Italy. Current programming interests include C, C++, C#, Linux, Unix, Mac OS X, Safe Code, encryption applications.
http://www.42yo.com

Comments and Discussions

 
GeneralSmall change suggested Pin
Russ Suter10-May-08 10:45
Russ Suter10-May-08 10:45 
GeneralRe: Small change suggested Pin
dfjklsdfjkljklm8-Jan-09 21:28
dfjklsdfjkljklm8-Jan-09 21:28 
QuestionLicense?? Pin
Coolite9-May-08 14:06
Coolite9-May-08 14:06 
Generalvery good Pin
laleh.rajabi1-Mar-08 1:14
laleh.rajabi1-Mar-08 1:14 
GeneralGreate !!! Pin
Abhijit Jana5-Dec-07 20:44
professionalAbhijit Jana5-Dec-07 20:44 
GeneralGood! Pin
montanacarlo25-Apr-07 22:30
montanacarlo25-Apr-07 22:30 
GeneralExamples Pin
Priyank Bolia24-Apr-07 6:52
Priyank Bolia24-Apr-07 6:52 
GeneralRe: Examples Pin
Elia Conchione25-Apr-07 20:50
Elia Conchione25-Apr-07 20:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.