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...

 

3 Comments

Comments have been disabled for this content.