我正在为我们编写的自定义SSIS组件创建一个安装程序。我想自动添加自定义组件,而不是要求用户手动添加它。如何以编程方式将自定义组件添加到Visual Studio工具箱?
我想这个代码做到这一点:
public void AddToolboxItem(string toolboxTabName, string toolBoxItemName, string toolBoxItemPath) {
Type dteReference;
EnvDTE.ToolBox toolBox;
EnvDTE80.ToolBoxItem2 addedToolBoxItem;
// Get a reference to the visual studio development environment.
dteReference = Type.GetTypeFromProgID("VisualStudio.DTE.9.0");
if(dteReference != null) {
// Get a reference to the toolbox of the development environment.
EnvDTE80.DTE2 dte = (EnvDTE80.DTE2)Activator.CreateInstance(dteReference);
toolBox = (EnvDTE.ToolBox)dte.Windows.Item("{B1E99781-AB81-11D0-B683-00AA00A3EE26}").Object;
// Loop through all tab pages to find the toolbox tab page that was specified
// in the toolboxTabName parameter.
foreach (EnvDTE80.ToolBoxTab2 toolBoxTab in toolBox.ToolBoxTabs) {
// Is this the right toolbox?
if(string.Compare(toolBoxTab.Name, toolboxTabName, true) == 0) {
// First check if the component is not already in the toolbox:
bool found = false;
foreach(EnvDTE80.ToolBoxItem2 toolBoxItem in toolBoxTab.ToolBoxItems) {
if (string.Compare(toolBoxItem.Name, toolBoxItemName, true) == 0) {
found = true;
break;
}
}
// The toolbox item is not in the toolbox tab, add it:
if (!found) {
addedToolBoxItem = (EnvDTE80.ToolBoxItem2)toolBoxTab.ToolBoxItems.Add(
toolBoxItemName,
toolBoxItemPath,
EnvDTE.vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent);
}
break;
}
}
}
}
我能到“数据流转换”工具箱选项卡的参考,但添加的项目未出现异常或错误失败。
我调用此函数与参数:
- toolboxTabName = “数据流转换”
- toolBoxItemName = “专用测试组件”
- toolBoxItemPath =“C:\ Program Files文件\ Microsoft SQL Server的\ 100个\ DTS \ PipelineComponents \ mdTest.dll”
其完整性检查,我尝试使用vsToolBoxItemFormatDotNETComponent枚举作为添加()的第三个参数。这会导致Add返回一个有效的对象(即成功),但新项目不会出现在工具箱上。我怀疑可能需要某种“保存”操作(即使我使Add()正常工作)。
有什么办法以编程方式向 工具箱添加SSIS组件?
所有我已经安装了工具已经取得了用户拖动到DLL工具箱。也许你会成为第一个破解:) – Sam 2010-12-21 21:03:15
安装SQL Server 2012时,安装到VS2010中的新BIDS会自动安装PipelineComponents中的所有组件。这似乎不是SQL Server 2012的问题。 – 2012-05-14 20:46:58