Micrsoft Visual Studio 2005 Beta 2 ToolBox integration

We have developed a Microsoft .NET Control library on .NET 1.1. We have added an installer to integrate that library into the Visual Studio 2003 ToolBox. This all works great. Now we are expanding this installer to make it possible to integrate into Microsoft Visual Studio 2005 (Beta 2 at this point), but we cannot add the actual controls to a Tab in the ToolBox.

To illustrate the problem, I have created a simple solution in Visual Studio 2003. This solution contains 2 projects: VisualStudioTest and VisualStudioTestControlLibrary. VisualStudioTest is a Windows Forms Application that can add the VisualStudioControlLibrary to Visual Studio 2003 and 2005.The Visual Studio 2003 code works. The Visual Studio 2005 code creates a tab, but does not add the controls to the tab. I have posted the code of the VisualStudioTest. The VisualStudioTestControlLibrary can be any control Library with WinForm Components / Controls

Can you tell me what I should do to make the Visual Studio 2005 ToolBox integration work

Remark: I cannot compile any code on .NET 2.0, because our Control library is 1.1 and it should stay that way because of backwards compatibility.

Kind regards,

Robin



using System;
using System.Globalization;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

using EnvDTE;

namespace VisualStudioTest
{
 /// <summary>
 /// Summary description for Form1.
 /// </summary>
 public class Form1 : System.Windows.Forms.Form
 {
  private System.Windows.Forms.Button btAddTo2003;
  private System.Windows.Forms.Button btDeleteFrom2003;
  private System.Windows.Forms.Button btDeleteFrom2005;
  private System.Windows.Forms.Button btAddTo2005;
  /// <summary>
  /// Required designer variable.
  /// </summary>
  private System.ComponentModel.Container components = null;

  public Form1()
  {
   //
   // Required for Windows Form Designer support
   //
   InitializeComponent();

   //
   // TODO: Add any constructor code after InitializeComponent call
   //
  }

  /// <summary>
  /// Clean up any resources being used.
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }

  #region Windows Form Designer generated code
  /// <summary>
  /// Required method for Designer support - do not modify
  /// the contents of this method with the code editor.
  /// </summary>
  private void InitializeComponent()
  {
   this.btAddTo2003 = new System.Windows.Forms.Button();
   this.btDeleteFrom2003 = new System.Windows.Forms.Button();
   this.btDeleteFrom2005 = new System.Windows.Forms.Button();
   this.btAddTo2005 = new System.Windows.Forms.Button();
   this.SuspendLayout();
   //
   // btAddTo2003
   //
   this.btAddTo2003.Location = new System.Drawing.Point(8, 16);
   this.btAddTo2003.Name = "btAddTo2003";
   this.btAddTo2003.Size = new System.Drawing.Size(160, 23);
   this.btAddTo2003.TabIndex = 0;
   this.btAddTo2003.Text = "Add to VS.NET 2003";
   this.btAddTo2003.Click += new System.EventHandler(this.btAddTo2003_Click);
   //
   // btDeleteFrom2003
   //
   this.btDeleteFrom2003.Location = new System.Drawing.Point(8, 48);
   this.btDeleteFrom2003.Name = "btDeleteFrom2003";
   this.btDeleteFrom2003.Size = new System.Drawing.Size(160, 23);
   this.btDeleteFrom2003.TabIndex = 1;
   this.btDeleteFrom2003.Text = "Delete from VS.NET 2003";
   this.btDeleteFrom2003.Click += new System.EventHandler(this.btDeleteFrom2003_Click);
   //
   // btDeleteFrom2005
   //
   this.btDeleteFrom2005.Location = new System.Drawing.Point(200, 48);
   this.btDeleteFrom2005.Name = "btDeleteFrom2005";
   this.btDeleteFrom2005.Size = new System.Drawing.Size(160, 23);
   this.btDeleteFrom2005.TabIndex = 3;
   this.btDeleteFrom2005.Text = "Delete from VS.NET 2005";
   this.btDeleteFrom2005.Click += new System.EventHandler(this.btDeleteFrom2005_Click);
   //
   // btAddTo2005
   //
   this.btAddTo2005.Location = new System.Drawing.Point(200, 16);
   this.btAddTo2005.Name = "btAddTo2005";
   this.btAddTo2005.Size = new System.Drawing.Size(160, 23);
   this.btAddTo2005.TabIndex = 2;
   this.btAddTo2005.Text = "Add to VS.NET 2005";
   this.btAddTo2005.Click += new System.EventHandler(this.btAddTo2005_Click);
   //
   // Form1
   //
   this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
   this.ClientSize = new System.Drawing.Size(376, 94);
   this.Controls.Add(this.btDeleteFrom2005);
   this.Controls.Add(this.btAddTo2005);
   this.Controls.Add(this.btDeleteFrom2003);
   this.Controls.Add(this.btAddTo2003);
   this.Name = "Form1";
   this.Text = "Visual Studio Test";
   this.ResumeLayout(false);

  }
  #endregion

  /// <summary>
  /// The main entry point for the application.
  /// </summary>
  [STAThread]
  static void Main()
  {
   Application.Run(new Form1());
  }

  /// <summary>
  /// Returns the tab with tabName from toolBox. Returns null when the tab does not exists
  /// </summary>
  private static EnvDTE.ToolBoxTab GetToolBoxTabWithName(EnvDTE.ToolBox toolBox, string tabName)
  {
   //delete a possible tab
   foreach (EnvDTE.ToolBoxTab tab in toolBox.ToolBoxTabs)
   {
    if ((tab.Name != null) && (String.Compare(tab.Name, tabName, true, CultureInfo.InvariantCulture) == 0))
    {
     return tab;
    }
   }
   return null;
  }

  private void AddToToolBox(string visualStudioProgID)
  {
   //Get the Type from the ProgID
   Type dteType = Type.GetTypeFromProgID(visualStudioProgID, true);

   //Create an instancen from it
   DTE dte = (DTE)Activator.CreateInstance(dteType);

   //Make the window visible so we can see it
   dte.MainWindow.Visible = true;

   //Get the ToolBox
   EnvDTE.ToolBox toolBox = (EnvDTE.ToolBox) dte.Windows.Item(EnvDTE.Constants.vsWindowKindToolbox).Object;

   //Get the Tab
   EnvDTE.ToolBoxTab tab = GetToolBoxTabWithName(toolBox, "MyControlLibrary");

   //Delete it if it did exist
   if (tab != null) tab.Delete();  

   //Create a new tab
   tab = toolBox.ToolBoxTabs.Add("MyControlLibrary");

   //Activate the tab
   tab.Activate();

   //Select the first item
   tab.ToolBoxItems.Item(1).Select();

   //Set the properties window to visible, this is just a workaround to
   //a bug in VS.NET 2003
   dte.Windows.Item(EnvDTE.Constants.vsWindowKindProperties).Visible = true;

   //Get the assembly location
   string assemblyPath = typeof(VisualStudioTestControlLibrary.MyTextBox).Assembly.Location;

   //Add the Controls from the ControlLibrary to the tab
   tab.ToolBoxItems.Add("MyControlLibrary", assemblyPath, EnvDTE.vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent);

   //Do not Quit the DTE, so we can see what happened
   //dte.Quit();
  }

  private void DeleteFromToolBox(string visualStudioProgID)
  {
   //Get the Type from the ProgID
   Type dteType = Type.GetTypeFromProgID(visualStudioProgID, true);

   //Create an instancen from it
   DTE dte = (DTE)Activator.CreateInstance(dteType);

   //Make the window visible so we can see it
   dte.MainWindow.Visible = true;

   //Get the ToolBox
   EnvDTE.ToolBox toolBox = (EnvDTE.ToolBox) dte.Windows.Item(EnvDTE.Constants.vsWindowKindToolbox).Object;

   //Get the Tab
   EnvDTE.ToolBoxTab tab = GetToolBoxTabWithName(toolBox, "MyControlLibrary");

   //Delete it if it did exist
   if (tab != null) tab.Delete();  

   //Do not Quit the DTE
   //dte.Quit();
  }

  private void btAddTo2003_Click(object sender, System.EventArgs e)
  {
   this.AddToToolBox("VisualStudio.DTE.7.1");
  }

  private void btDeleteFrom2003_Click(object sender, System.EventArgs e)
  {
   this.DeleteFromToolBox("VisualStudio.DTE.7.1");
  }

  private void btAddTo2005_Click(object sender, System.EventArgs e)
  {
   this.AddToToolBox("VisualStudio.DTE.8.0");  
  }

  private void btDeleteFrom2005_Click(object sender, System.EventArgs e)
  {
   this.DeleteFromToolBox("VisualStudio.DTE.8.0");
  }
 }
}



 




Answer this question

Micrsoft Visual Studio 2005 Beta 2 ToolBox integration

  • Patrick D.

    This is actually a bug in the WinForms designer and the Extensibility team has decided to depricate this method of adding .Net user controls to the toolbox in favor of a new way of adding controls. You can now add .Net controls using theVisual Studio Community Content installer. This executable, VSContentInstaller.exe, is available under \Program Files\Common Files\Microsoft Shared\MSEnv.
    This installer requires you to package the contents for your controls using a vscontent file and then package that as a .vsi file. We curretnly have a comminuty tool that helps create such vsi files. You can find information and install location about this tool at Craig Skibo's blog entry about this Power Toy (http://blogs.msdn.com/craigskibo/archive/2005/08/12/451017.aspx).

    Thanks,
    Chetan


  • Fro-D

    Help, help..........
    We are facing the same problem. All the codes originally worked in VS .NET 2003.
    But in VS .NET 2005, only the Tab is added but not control.

    So anyone has solved this issue in VS .NET 2005 Beta2



  • VCplusplus_Neophyte

    To add to the other comments:

    1) The power toy application seems to be broken, as it fails on an incorrect version of the .Zip library (it wants 1.0.0.0, but ships with 8.0.0.0)

    2) I need to install the controls across all users, not just the current user. From my understanding, the recommended method is to create a .vsi file and then call the VSContentInstaller.exe, which then puts the controls into the user's My Documents folder. It does not appear to have a silent mode, so the better solution seems to be to place the controls in the \My Documents\Visual Studio 2005\Controls and then call Tools.InstallCommunityControls.

    3) How do I uninstall I ended up using the old (deprecated) mechanism, which allows me to at least delete the tab, and with it all the controls.

    Is there a better mechanism Either way, as a control developer, it's very clumsy to implement and deploy.

    -Ingo

  • Cameron84

    Tim,

    Nope, sorry, i have tried everything. But I think it is just a bug in VS.NET 2005 Beta 2. Hope RTM doesn't have it.

  • basquini

    Hello Robin,

    Did you manage to resolve this issue We are facing the same difficulty.

    Tim

  • Jennifer Xu

    Chetan,

    From my understanding of VSI, there are a few limitations.

    The first is that it is user specific, which makes sense for samples and similar, but not for components that would be used on a machine by several users.

    Second is that it does not cover additional Toolbox Items such as those for SQL Server Integration Services (SSIS).

    My components and interest in this area is exclusively for SSIS components, so VSI will not cover it. This seems a like a hole in the product, that you can professional install components as part of an install.


  • Sai Shyam

    What if I have an .msi for my component that includes the control, documentation, code examples, requires some custom installation steps such as IIS directory creation. I think I want to use .msi for that. But I still want to put my control into the toolbox in VS.NET 2005. I cannot see how I can use .vsi from within .msi I hope those guys who made installing controls to toolbox that complex were fired.
  • Micrsoft Visual Studio 2005 Beta 2 ToolBox integration