void InstallControl() { // Create an instance of the VS IDE, Type type = System.Type.GetTypeFromProgID("VisualStudio.DTE.10.0"); DTE dte = (DTE)System.Activator.CreateInstance(type, true); // create a temporary winform project; string tmpFile = Path.GetFileNameWithoutExtension(Path.GetTempFileName()); string tmpDir = string.Format("{0}{1}", Path.GetTempPath(), tmpFile); Solution2 solution = dte.Solution as Solution2; string templatePath = solution.GetProjectTemplate("WindowsApplication.zip", "CSharp"); Project proj = solution.AddFromTemplate(templatePath, tmpDir, "dummyproj", false); // add the control to the toolbox. EnvDTE.Window window = dte.Windows.Item(EnvDTE.Constants.vsWindowKindToolbox); EnvDTE.ToolBox toolbox = (EnvDTE.ToolBox)window.Object; EnvDTE.ToolBoxTab myTab = toolbox.ToolBoxTabs.Add("Saino"); myTab.Activate(); myTab.ToolBoxItems.Add("MyUserControl", ctrlPath, vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent); dte.Solution.Close(false); Marshal.ReleaseComObject(dte); //Console.WriteLine("Control Installed!!!"); }
void UninstallControl() { Type type = System.Type.GetTypeFromProgID("VisualStudio.DTE.10.0"); DTE dte = (DTE)System.Activator.CreateInstance(type, true); EnvDTE.Window window = dte.Windows.Item(EnvDTE.Constants.vsWindowKindToolbox); EnvDTE.ToolBox toolbox = (EnvDTE.ToolBox)window.Object; EnvDTE.ToolBoxTab myTab = toolbox.ToolBoxTabs.Item("Saino"); myTab.Activate(); myTab.Delete(); Marshal.ReleaseComObject(dte); //Console.WriteLine("Control Uninstalled!!!"); }