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

Command line application to install components into ToolBox

Rate me:
Please Sign up or sign in to vote.
4.31/5 (6 votes)
20 Sep 20052 min read 31K   384   24   5
An article on installing components to VS ToolBox.

Introduction

This article presents a console application that allows to create or delete a ToolBox tab and fill it with components of one or more assemblies. This article extends the Serkan Inci article (although I’ve not started from his code, I’ve found there the trick of activating a Property window).

The generated EXW file can be easily run from any installer, hiding its command window.

Background

Basic familiarity with Visual Studio .NET and C# is necessary for this article. Experience on DTE and Reflection is a plus.

Using the code

To use the EXE file to install a DLL, simply launch:

ElToolBoxInstaller.exe -i TabName FirstDllFullPath 
                   [SecondDllFullPath]  [ThirdDllFullPath] ….

Note that you have to pass the assembly's full path.

To use the EXE file to delete a tab, simply launch:

ElToolBoxInstaller.exe -u TabName

Design specifics are that:

  1. All components of an assembly are going to be installed on the same tab.
  2. With a single command it is possible to install components from multiple assemblies under the same tab.
  3. Visual Studio will be closed during installation (the software checks for this).
  4. All versions of Visual Studio have to be updated.

About point 1, I will probably update the code to allow to send components of the same assembly to different tabs (it wasn’t necessary for my products till now, but I think there’s an easy way of installing all components to a tab and then moving them).

Point 2 is important to avoid reopening a DTE several times.

Point 3 is a limitation that helps to prevent bad results and unnecessary complications (you could easily update code to link an open Visual Studio instance, but you should update the ToolBox of all instances and I’ve found some strange effects when the development environment was in debug mode).

First of all the program checks if a Visual Studio instance is running, looking for a "devenv" process.

C#
private static bool IsVSActive()
{
    //"Checking if Vs is open"
    try
    {
        Process[] processArray1 = Process.GetProcesses();
        for (int num1 = 0; num1 < processArray1.Length; num1++)
        {
            Process process1 = processArray1[num1];
            if (string.Compare(process1.ProcessName, "devenv", 
                     true, CultureInfo.InvariantCulture) == 0)
            {
                return true;
            }
        }
    }
    catch (Exception e)
    {
        Console.WriteLine(e.ToString());
    }
    return false;
}

Once verified that no VS instance is running, the program proceeds.

The higher level function is InstallOnVs, it receives as argument a ProgId string (for example: “VisualStudio.DTE.7.1” for Visual Studio 2003) and an array of strings that must contain:

  1. –i (to install) or –u (to uninstall)
  2. tab name
  3. one or more assembly full paths

InstallOnVs first creates a ToolBox window:

C#
//"Get DTE type"
Type type1 = Type.GetTypeFromProgID(progId);
        
// Version of VS is not installed 
if (type1 == null) return;
// Create DTE
dte1 = (DTE) Activator.CreateInstance(type1);
// Get ToolBox Window
Window window1 = dte1.Windows.Item(Constants.vsWindowKindToolbox);
box1 = (ToolBox) window1.Object;
private static void tabActivate()
{
    //Basically a trick to fix some strange behaviour of DTE
    dte1.ExecuteCommand("View.PropertiesWindow", "");
    
    tab2.Activate();
    
    //"Select first tab item"
    tab2.ToolBoxItems.Item(1).Select();
}

Finally all assemblies are loaded using AddtoToolBox.

C#
private static void AddToToolBox(string assemblyfullpath)
{
    try
    {
        //Check if file exists
        FileInfo info1 = new FileInfo(assemblyfullpath);
        if (info1.Exists)
        {
            tab2.ToolBoxItems.Add(tabName, assemblyfullpath, 
              vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent);
        }
    }
    catch (Exception e)
    {
        Console.WriteLine(e.Message.ToString());
    }
}

Although the task is not so complex I wasn’t able to find a “ready to go” solution, I hope now this will save your time.

History

First version submitted - 07 September 2005.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Italy Italy
Roberto is cofounder of EuclidLabs, a young company developing robotics appications and .Net components.
He has several years of experience in programming industrial applications around the world, both on PC side (C, C++, VB, C#) and CNC side (G code, FANUC and KUKA robot language).
When he is not travelling or programming he is usually involved in quite dangerous activity (boxing and martial arts, parachute, shopping with girlfriend).

If you have a really challenging robotics problem feel free to contact him at roberto.polesel@euclidlabs.it

---
Science may set limits to knowledge, but should not set limits to imagination.
Bertrand Russell

Comments and Discussions

 
NewsThere is a free tool for do that on VS2005 Pin
www.issoft.eu13-Sep-07 1:13
www.issoft.eu13-Sep-07 1:13 
GeneralI need this for .NET 2005 Pin
Pink Floyd8-Mar-06 9:16
Pink Floyd8-Mar-06 9:16 
GeneralRe: I need this for .NET 2005 Pin
Pink Floyd10-Mar-06 7:52
Pink Floyd10-Mar-06 7:52 
Ok, in case someone may need this, I found a complete thread and solution to this in .NET 2005 here:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=126572&SiteID=1&PageID=0[^]

Hope it helps.
GeneralSuggestion for future versions Pin
Yuri Zholobov11-Oct-05 4:56
Yuri Zholobov11-Oct-05 4:56 
GeneralRe: Suggestion for future versions Pin
Roberto Polesel21-Oct-05 4:25
Roberto Polesel21-Oct-05 4:25 

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.