我正在爲我們編寫的自定義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