Thursday, April 10, 2003 5:31 PM Shawn A. Van Ness

Revenge of the Toolbox: VS 2003

A few weeks ago, I blogged about how to programmatically add .NET UserControls to a VS Toolbox tab.

Today my teammates and I got around to testing/updating the code for VS 2003 -- as it happens, the code I presented in the blog is correct, but in practice getting it to work proved to be another royal p.i.t.a....

This time, the problem we ran into lied in how we were automating VS:  by instantiating a new instance of EnvDTE.DTE, from outside the devenv.exe process. 

For VS 7.0, we went about this by cavalierly instantiating the managed wrapper for the VS automation model:  dte = new EnvDTE.DTE();  No problem, right?

But guess what -- the managed wrapper for VS (EnvDTE.dll) that's shipping with the v1.1 framework is binary identical to the one in v1.0 framework!  No kidding!  They point to the same underlying CLSID, which, as it happens, is the old (VS 7.0) CLSID. 

All of the VS automation interfaces are the same, so I guess MS decided they didn't need to ship a new PIA for VS 7.1.  But the CLSIDs have changed, in order to support side-by-side coexistance of VS 7.0 and 7.1...  and the PIA contains references to the CLSIDs!  Kaboom.  For our little use-case, anyway.

In the end, we determined the best/easiest thing to do was to instantiate the RCW by going through the version-independent ProgID (which seems to correctly point to the latest):

            // Get DTE from version-indep progid (points to newest)
            Type latestDTE = Type.GetTypeFromProgID("VisualStudio.DTE");
            EnvDTE.DTE dte = Activator.CreateInstance(latestDTE) as EnvDTE.DTE;

Hope that helps somebody...

 

Comments

# re: Revenge of the Toolbox: VS 2003

Tuesday, April 15, 2003 10:15 PM by Ralfoide

Both your blog entries are very helpful.
I fighted with adding the toolbox item for quite a while!
Regards,

# re: Revenge of the Toolbox: VS 2003

Tuesday, June 3, 2003 10:20 PM by bb

oh man - thanks for this - I just spent 2 hours trying to figure out why it doesn't have the correct clsid. Beautiful solution.

- me

# re: Revenge of the Toolbox: VS 2003

Monday, July 12, 2004 1:58 AM by Walt Ritscher - Thinking about code

Thanks Shawn. Solved a problem I have been spending too many hours one.
See my site for the details.