5,557,686 members and growing! (14,558 online)
Email Password   helpLost your password?
Web Development » ASP.NET » General     Intermediate License: The Code Project Open License (CPOL)

Visual Studio 2005 Toolbox Utility

By Jon Person

This useful utility makes it easy to install or uninstall user controls to the Visual Studio 2005 toolbox.
Windows, .NET, Visual Studio, ASP.NET, Dev

Posted: 28 Apr 2006
Updated: 28 Apr 2006
Views: 51,451
Bookmarked: 45 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
9 votes for this Article.
Popularity: 3.51 Rating: 3.68 out of 5
2 votes, 22.2%
1
0 votes, 0.0%
2
1 vote, 11.1%
3
1 vote, 11.1%
4
5 votes, 55.6%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Introduction

If you have ever tried to write a user control in Visual Studio.NET, you'll already know that the process is bittersweet.  On one hand, writing the control itself is painless and Visual Studio 2005 has greatly improved the process of making controls work on multiple .NET platforms via design-time attributes and "asmmeta" assemblies.  On the other hand, however, deploying controls and adding them to the Toolbox is a process rife with errors.  It is definitely not a matter of adding a registry key (as I would have liked to see).

After getting a lot of e-mails from customers asking me how to add real-time GPS controls to their Toolbox, I decided that I needed to come up with some kind of utility to get the job done.  Visual Studio 2005 does already have some mechanisms for installing user controls, such as ".vsi" files, but unfortunately this approach typically results in a "Package Load Failure" and does not have a guarantee to work on every VS2005 installation.  Fortunately, Chetan Chudasama generously gave out source code in his blog which explains how to add or remove Toolbox controls using code and the "DTE" (Design-Time Environment) for Visual Studio.  Thanks to his efforts, I was able to turn the code into a command-line utility which is well-suited for installers (which is usually when Toolbox controls are installed).

This article describes how to use the utility and integrate it into your own installers.  You are welcome to redistribute this utility and I consider it freeware. 

Usage

The Toolbox utility is a single executable which processes one or more tasks via the command-line.  Since the Toolbox itself can change depending on whether you are working with Desktop Framework 2.0 or Compact Framework 2.0 applications, different commands exist which let you add desktop or mobile device controls.  I have optimized the utility to minimize the calls to the DTE and it runs a couple of seconds faster than Chetan's code if you have multiple assemblies to install.

When the utility runs, the following window will appear.  Since the utility must launch a hidden instance of Visual Studio 2005 (devenv.exe), this can be a time-consuming process.  A progress bar helps to show that something is actually happening during Toolbox modifications:

Screen shot of the Toolbox Utility

I kept the window free from company logos and branding so it will look like your own utility.  The command line must follow the following syntax:

Toolbox.exe [/silent] /installdesktop  assembly toolbox_tab [...]
Toolbox.exe [/silent] /installpocketpc assembly toolbox_tab [...]
Toolbox.exe [/silent] /installcustom template assembly toolbox_tab [...]
Toolbox.exe [/silent] /uninstall toolbox_tab [...]
... each command is as follows:
/silent          Suppresses all output during installation or uninstallation.
/installdesktop  Installs controls written for Desktop Framework 2.0 to the toolbox.
/installpocketpc Installs controls written for Compact Framework 2.0 to the toolbox.
/installcustom   Installs controls written for a specific kind of device project to the toolbox.
/uninstall       Removes an entire Toolbox tab.
[...]            Multiple install commands can be appended to install/uninstall multiple controls at one time.
... and the parameters for each command are:
"assembly"    is the absolute path to an assembly containing user controls.
"toolbox_tab" is the name of the Toolbox Tab where control should be installed.
"template"    is the name of a ZIP file from the Templates folder indicating a specific kind of project.
The utility can install or uninstall any number of controls in one call, which is important since about 3-5 seconds are required just to launch and shut down Visual Studio 2005. The commands will vary depending on which Toolbox you need to modify.

Installing Desktop User Controls

To install desktop controls, you must use the /installdesktop command and pass in the path to an assembly as well as the name of the Toolbox tab to add the control to:
Toolbox.exe /installdesktop "C:\MyUserControl.dll" "My Toolbox Tab Name"

Installing PocketPC User Controls

To install mobile device controls, such as PocketPC controls for Windows Mobile 2003, you must use the /installpocketpc command and pass in the path to an assembly as well as the name of the Toolbox tab to add the control to:
Toolbox.exe /installpocketpc "C:\MyUserControl.PocketPC.dll" "My Toolbox Tab Name (PocketPC)"

... if you provide the same user controls for multiple platforms, you should add "(PocketPC)" to the Toolbox tab name to keep the controls separated.

Installing User Controls for Custom Toolboxes

To install controls for platforms not yet released at the time of this article, you must use the /installcustom command and pass in a "template name" along with the path to an assembly, as well as the name of the Toolbox tab to add the control to. The template is the filename of a template ZIP file. You can typically find ZIP files here:
\Program Files\Microsoft Visual Studio 8\Common7\IDE\ProjectTemplates\CSharp\

... you don't need the name of the directory since Visual Studio 2005 keeps all of the ZIP file names unique. The following example installs controls for Smartphone:

Toolbox.exe /installcustom "Smartphone2003-WindowsApplication.zip" 
"C:\MyUserControl.Smartphone.dll" "My Toolbox Tab Name (Smartphone)"

Uninstalling Controls

There is no mechanism for uninstalling a single control from the Toolbox; entire Toolbox tabs are deleted at one time. This is another reason why it's a good idea to add text to the Toolbox tab name to keep controls separate per platform. To uninstall a Toolbox tab, specify the full tab name:
Toolbox.exe /uninstall "My Toolbox Tab"

Clean Re-Installation of Controls

The Toolbox is not smart enough to know when controls already exist in a tab. This can cause problems because the same control would get added multiple times! To solve this problem, begin the command line with an /uninstall command immediately before an install command. This will cleanly re-install the toolbox controls:
Toolbox.exe /uninstall "My Toolbox Tab" /installdesktop "C:\MyUserControl.dll" "My Toolbox Tab"

Silent Operation

If for some reason you don't want the progress bar to display, add the /silent command to the command line:
Toolbox.exe /silent /uninstall "My Toolbox Tab" /uninstall "Another Toolbox Tab"

Summary

The experience of designing user controls for Visual Studio 2005 has improved greatly over Visual Studio 2003, but the process of installing a custom user control is still tedius. Perhaps the folks at Microsoft could use the registry to search for and install custom user controls, much like the AssemblyFolders registry key is used to locate custom assemblies. This change would vastly simplify installation of custom user controls in the future.

If you find any bugs or wish to see improvements, you can post in the thread on my web site for this utility, located here: Toolbox Utility Forum.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Jon Person


Jon Person is a component developer for desktop and mobile devices using .NET. His company, "GeoFrameworks," maintains the award-winning "GPS.NET" component now in use by hundreds of companies around the globe. Jon's articles have appeared in Dr. Dobb's Journal and have earned him the rank of one of CodeProject's "Most Helpful Members of 2004." In his spare time, Jon enjoys storm chasing in the Great Plains. On May 4th, 2007, Jon witnessed the two-mile-wide tornado that destroyed Greensburg, Kansas. He then volunteered for a month to help residents reclaim their lives, running GeoFrameworks from a hotel room with no TV or running water and using his GPS and .NET mapping component "GIS.NET" to manage volunteer jobs around the stricken town. A photo journal of this experience is up on Flickr.

Jon believes in assisting other small businesses, and maintains some open-source projects such as the Visual Studio Toolbox Utility on CodePlex. Jon enjoys helping other developers become coding ninjas and he welcomes all questions, comments and suggestions via e-mail at jperson@geoframeworks.com.

NOTE: None of the articles I publish require any GeoFrameworks software listed below:


Occupation: President
Company: GeoFrameworks, LLC
Location: United States United States

Other popular ASP.NET articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 17 of 17 (Total in Forum: 17) (Refresh)FirstPrevNext
Subject  Author Date 
NewsThis project has been moved to CodePlexmemberJon Person20:29 23 Jan '08  
GeneralIt does work for me..memberRmaman5:33 13 Jun '07  
QuestionWhat changes are necessary for this to work with VB/C# 2005 Express?memberKevinHall11:09 24 May '07  
GeneralSource Code Now AvailablememberJon Person13:21 28 Nov '06  
GeneralRe: Source Code Now Availablememberlgaudouen21:59 30 Nov '06  
GeneralRe: Source Code Now AvailablememberJon Person12:40 5 Dec '06  
GeneralRe: Source Code Now Availablememberotrack19:47 15 Mar '07  
GeneralRe: Source Code Now Availablememberotrack6:12 16 Mar '07  
GeneralRe: Source Code Now AvailablememberJon Person20:30 23 Jan '08  
GeneralRe: Source Code Now AvailablememberDaniel Cazzulino [Solution Architect MVP]7:26 11 Apr '07  
GeneralRe: Source Code Now AvailablememberJon Person7:38 11 Apr '07  
GeneralThrows SystemNullExceptionsmemberXH_expanders13:01 28 Nov '06  
AnswerRe: Throws SystemNullExceptionsmemberJon Person13:19 28 Nov '06  
GeneralRe: Throws SystemNullExceptionsmembermail8659513:03 5 Dec '06  
GeneralRe: Throws SystemNullExceptionsmemberJon Person20:32 23 Jan '08  
GeneralExcellent, thanks! [modified]memberqjdnnbfjqyyk5:08 17 Aug '06  
GeneralRe: Excellent, thanks!memberWolfMoon4:17 30 Aug '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 28 Apr 2006
Editor:
Copyright 2006 by Jon Person
Everything else Copyright © CodeProject, 1999-2008
Web16 | Advertise on the Code Project