Feed on
Posts
Comments

What a pain in the neck the last couple hours have been.

I’ve been writing a installer application that will add some of our custom components to the Visual Studio toolbox.  I wrote a console app that does the work, only took about 30 minutes to put together.  When the testing started however, I got a migraine.

The code to add a tab to the toolbox is a bit quirky (selecting the toolboxItem for example) but easy enough to understand.

... more code not shown...

If targetTab Is Nothing Then
  targetTab = tabs.Add("Scandia Tools")
End If

targetTab.Activate()
env.ExecuteCommand("View.PropertiesWindow", "")targetTab.ToolBoxItems.Item(1).Select()

Dim tabItem As ToolBoxItem = targetTab.ToolBoxItems.Add("ControlName",       path, vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent)

Quite simply, it didn’t work.  After spelunking around for a while I finally figured out that Visual Studio.NET 2002 was being launched by my app, not VS 2003.  Sure enough, my new toolbox tab was being added to VS 2002.  I was fortunate enough, if you want to think of it that way, to be testing on a machine that had both versions of the framework installed so I caught this bug immediately.

Thanks to Shawn Van Ness and his blog I found the answer.  Turns out Microsoft did not update the version 1.0 of EnvDTE.dll when they released version 1.1.  Since .NET simply has a managed wrapper for the COM automation interface this poses a serious problem in scenarios like mine.

Heres a bit from Shawns blog:

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 coexistence of VS 7.0 and 7.1…  and the PIA contains references to the CLSIDs! 

Shawn posted some C# code on his site that shows how to instantiate the newest version of the ‘VisualStudio.DTE’ which solves the problem.

Here is the VB version - Hope this helps any one having the same problem.

 

' Get DTE from version-indep progid (points to newest)
Dim latestDTE As Type = Type.GetTypeFromProgID("VisualStudio.DTE")

Dim env As EnvDTE.DTE
env = CType(Activator.CreateInstance(latestDTE), EnvDTE.DTE)
Comments

# re: Toolbox Stupidity - Visual Studio 2003 7/11/2004 11:20 PM Shawn A. Van Ness

Cool Walt — glad I could help! Be sure to mind the other advice on that thread — re checking for running instances of VS, and hooking in a custom OLE message filter.

http://weblogs.asp.net/savanness/archive/2003/04/24/6012.aspx

http://weblogs.asp.net/savanness/archive/2003/04/15/5701.aspx

http://weblogs.asp.net/savanness/archive/2003/04/10/5352.aspx

http://weblogs.asp.net/savanness/archive/2003/03/18/4019.aspx

-S


Leave a Reply