Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Command line application to install components into ToolBox

0.00/5 (No votes)
20 Sep 2005 1  
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.

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:

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

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