private void GetDllListTreeNode(string dllPath, ref TreeNode rootNode, ref int count) { //避免陷入死循环 if (count > 1000) { return; } string dllName = Path.GetFileNameWithoutExtension(dllPath); List <string> subRefDlls = DllRefReflectUtility.GetRefDlls(dllPath); if (subRefDlls == null || subRefDlls.Count < 1) { return; } count++; foreach (string subRef in subRefDlls) { if (subRef.StartsWith("System") || subRef.StartsWith("mscorlib") || subRef == dllName) { continue; } TreeNode subNode = rootNode.Nodes.Add(subRef); List <string> similarDlls = new List <string>(); this.FindSimilarDlls(_dirModel, subRef, ref similarDlls); if (similarDlls.Count < 1) { continue; } GetDllListTreeNode(similarDlls[0], ref subNode, ref count); } }
public frmDllRefFileCopy(DTE2 app) { InitializeComponent(); _app = app; List <Project> pros = ProjectUtility.GetAllProjects(_app); if (pros != null && pros.Count > 0) { for (int i = 0; i < pros.Count; i++) { this.combProjects.Items.Add(pros[i].Name); } this.combProjects.Tag = pros; } this.LoadUserConfig(); DllRefReflectUtility.ClearTempFiles(); DllRefReflectUtility.SubDirGuid = Guid.NewGuid().ToString(); }
private void CopySubRefDlls(string dllPath, string destDir, string dllRootDir, ref int count) { //避免陷入死循环 if (count > 1000) { return; } string dllName = Path.GetFileNameWithoutExtension(dllPath); List <string> subRefDlls = DllRefReflectUtility.GetRefDlls(dllPath); if (subRefDlls == null || subRefDlls.Count < 1) { return; } count++; foreach (string subRef in subRefDlls) { if (subRef.StartsWith("System") || subRef.StartsWith("mscorlib") || subRef == dllName) { continue; } List <string> similarDlls = new List <string>(); this.FindSimilarDlls(_dirModel, subRef, ref similarDlls); if (similarDlls.Count < 1) { continue; } string destFilePath = Path.Combine(destDir, Path.GetFileName(similarDlls[0])); if (_copiedFiles.Contains(destFilePath)) { continue; } _copiedFiles.Add(destFilePath); File.Copy(similarDlls[0], destFilePath, true); CopySubRefDlls(similarDlls[0], destDir, dllRootDir, ref count); } }
/// <summary>实现 IDTExtensibility2 接口的 OnConnection 方法。接收正在加载外接程序的通知。</summary> /// <param term='application'>宿主应用程序的根对象。</param> /// <param term='connectMode'>描述外接程序的加载方式。</param> /// <param term='addInInst'>表示此外接程序的对象。</param> /// <seealso class='IDTExtensibility2' /> public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { _app = (DTE2)application; _addIn = (AddIn)addInInst; if (connectMode == ext_ConnectMode.ext_cm_UISetup || connectMode == ext_ConnectMode.ext_cm_AfterStartup || connectMode == ext_ConnectMode.ext_cm_Startup) { object[] contextGUIDS = new object[] { }; Commands2 commands = (Commands2)_app.Commands; Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_app.CommandBars)["MenuBar"]; CommandBarControl cmdCtr = this.GetExistCommandBarControl(menuBarCommandBar, "李仙伟"); if (cmdCtr != null) { cmdCtr.Visible = true; return; } CommandBarControl myToolsControl = menuBarCommandBar.Controls.Add(MsoControlType.msoControlPopup, Missing.Value, Missing.Value, Missing.Value, Missing.Value); myToolsControl.Caption = "李仙伟"; CommandBarPopup toolsPopup = (CommandBarPopup)myToolsControl; //如果希望添加多个由您的外接程序处理的命令,可以重复此 try/catch 块, // 只需确保更新 QueryStatus/Exec 方法,使其包含新的命令名。 try { //将一个命令添加到 Commands 集合: Command command = this.GetExistCommand(commands, "PlatformSetting"); if (command == null) { command = commands.AddNamedCommand2(_addIn, "PlatformSetting", "目标平台设置(&P)", "批量修改目标平台", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); } //将对应于该命令的控件添加到“李仙伟”菜单: if ((command != null) && (toolsPopup != null)) { command.AddControl(toolsPopup.CommandBar, 1); } } catch (System.ArgumentException) { //如果出现此异常,原因很可能是由于具有该名称的命令 // 已存在。如果确实如此,则无需重新创建此命令,并且 // 可以放心忽略此异常。 } try { Command command = this.GetExistCommand(commands, "OutPathSetting"); if (command == null) { command = commands.AddNamedCommand2(_addIn, "OutPathSetting", "输出路径设置(&O)", "批量修改输出路径设置", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); } if ((command != null) && (toolsPopup != null)) { command.AddControl(toolsPopup.CommandBar, 2); } } catch (System.ArgumentException) { } try { Command command = this.GetExistCommand(commands, "BuildEventSetting"); if (command == null) { command = commands.AddNamedCommand2(_addIn, "BuildEventSetting", "生成事件设置(&E)", "批量修改生成事件", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); } if ((command != null) && (toolsPopup != null)) { command.AddControl(toolsPopup.CommandBar, 3); } } catch (System.ArgumentException) { } try { Command command = this.GetExistCommand(commands, "NetFrameweorkSetting"); if (command == null) { command = commands.AddNamedCommand2(_addIn, "NetFrameweorkSetting", ".NET版本设置(&N)", "批量修改.NET版本", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); } if ((command != null) && (toolsPopup != null)) { command.AddControl(toolsPopup.CommandBar, 4); } } catch (System.ArgumentException) { } try { Command command = this.GetExistCommand(commands, "CollapseAll"); if (command == null) { command = commands.AddNamedCommand2(_addIn, "CollapseAll", "折叠所有项目(&C)", "折叠所有项目", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); } if ((command != null) && (toolsPopup != null)) { command.AddControl(toolsPopup.CommandBar, 5); } } catch (System.ArgumentException) { } try { Command command = this.GetExistCommand(commands, "ExpandAll"); if (command == null) { command = commands.AddNamedCommand2(_addIn, "ExpandAll", "展开所有项目(&X)", "展开所有项目", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); } if ((command != null) && (toolsPopup != null)) { command.AddControl(toolsPopup.CommandBar, 6); } } catch (System.ArgumentException) { } try { Command command = this.GetExistCommand(commands, "MultiLoadProjects"); if (command == null) { command = commands.AddNamedCommand2(_addIn, "MultiLoadProjects", "批量加载项目", "批量加载项目", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); } if ((command != null) && (toolsPopup != null)) { command.AddControl(toolsPopup.CommandBar, 7); } } catch (System.ArgumentException) { } try { Command command = this.GetExistCommand(commands, "MultiCreateProjects"); if (command == null) { command = commands.AddNamedCommand2(_addIn, "MultiCreateProjects", "批量创建项目", "批量创建项目", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); } if ((command != null) && (toolsPopup != null)) { command.AddControl(toolsPopup.CommandBar, 8); } } catch (System.ArgumentException) { } try { Command command = this.GetExistCommand(commands, "DllRefConfig"); if (command == null) { command = commands.AddNamedCommand2(_addIn, "DllRefConfig", "修改项目dll引用", "修改项目dll引用", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); } if ((command != null) && (toolsPopup != null)) { command.AddControl(toolsPopup.CommandBar, 9); } } catch (System.ArgumentException) { } try { Command command = this.GetExistCommand(commands, "DllRefFileCopy"); if (command == null) { command = commands.AddNamedCommand2(_addIn, "DllRefFileCopy", "拷贝dll的引用(依赖项)", "拷贝dll的引用(依赖项)", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); } if ((command != null) && (toolsPopup != null)) { command.AddControl(toolsPopup.CommandBar, 10); } } catch (System.ArgumentException) { } try { Command command = this.GetExistCommand(commands, "Dll2Lib"); if (command == null) { command = commands.AddNamedCommand2(_addIn, "Dll2Lib", "更新dll到Lib", "更新dll到Lib", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); } if ((command != null) && (toolsPopup != null)) { command.AddControl(toolsPopup.CommandBar, 11); } } catch (System.ArgumentException) { } try { Command command = this.GetExistCommand(commands, "SQLCreator"); if (command == null) { command = commands.AddNamedCommand2(_addIn, "SQLCreator", "SQL语句生成器", "SQL语句生成器", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); } if ((command != null) && (toolsPopup != null)) { command.AddControl(toolsPopup.CommandBar, 12); } } catch (System.ArgumentException) { } try { Command command = this.GetExistCommand(commands, "GuidCreator"); if (command == null) { command = commands.AddNamedCommand2(_addIn, "GuidCreator", "Guid生成器", "Guid生成器", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); } if ((command != null) && (toolsPopup != null)) { command.AddControl(toolsPopup.CommandBar, 13); } } catch (System.ArgumentException) { } try { Command command = this.GetExistCommand(commands, "CheckRepeatDll"); if (command == null) { command = commands.AddNamedCommand2(_addIn, "CheckRepeatDll", "检查Lib库重复的dll", "检查Lib库重复的dll", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); } if ((command != null) && (toolsPopup != null)) { command.AddControl(toolsPopup.CommandBar, 14); } } catch (System.ArgumentException) { } try { Command command = this.GetExistCommand(commands, "Selection2Upper"); if (command == null) { command = commands.AddNamedCommand2(_addIn, "Selection2Upper", "Selection2Upper", "Selection2Upper", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); } if ((command != null) && (toolsPopup != null)) { command.AddControl(toolsPopup.CommandBar, 15); } } catch (System.ArgumentException) { } try { Command command = this.GetExistCommand(commands, "AboutMe"); if (command == null) { command = commands.AddNamedCommand2(_addIn, "AboutMe", "关于(&A)", "关于", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); } if ((command != null) && (toolsPopup != null)) { command.AddControl(toolsPopup.CommandBar, 16); } } catch (System.ArgumentException) { } } //清理临时文件 DllRefReflectUtility.ClearTempFiles(); }
private void rMenuCopySelRefDlls_Click(object sender, EventArgs e) { if (this.dataGridView1.SelectedRows == null || this.dataGridView1.SelectedRows.Count < 1) { return; } string dllRootDir = this.txtLibRootDir.Text.Trim(); if (string.IsNullOrEmpty(dllRootDir) || Directory.Exists(dllRootDir) == false) { MsgBox.ShowTip("请先输入Lib根目录"); return; } string destDir = this.txtDestDir.Text.Trim(); if (string.IsNullOrEmpty(destDir) || Directory.Exists(destDir) == false) { MsgBox.ShowTip("请先输入目标路径"); return; } CopyStrategyModel strategy = this.lblSetHideRefStrategy.Tag as CopyStrategyModel; if (strategy == null) { strategy = new CopyStrategyModel(); } strategy.DeepCopy = this.chkDeepCopy.Checked; strategy.CopyHideRefDlls = this.chkCopyHideRefDlls.Checked; _copiedFiles.Clear(); _dirModel = FileDirUtility.ReadAllDirAndFiles(dllRootDir); this.Cursor = Cursors.WaitCursor; for (int i = 0; i < this.dataGridView1.SelectedRows.Count; i++) { DataGridViewRow selRow = this.dataGridView1.SelectedRows[i]; Reference dllRef = selRow.Tag as Reference; if (dllRef == null) { continue; } string dllPath = dllRef.Path; if (string.IsNullOrEmpty(dllPath) || File.Exists(dllPath) == false) { continue; } List <string> subRefDlls = DllRefReflectUtility.GetRefDlls(dllPath); if (subRefDlls == null || subRefDlls.Count < 1) { continue; } foreach (string subRef in subRefDlls) { if (subRef.StartsWith("System") || subRef.StartsWith("mscorlib")) { continue; } if (subRef == dllRef.Name) { continue; } List <string> similarDlls = new List <string>(); this.FindSimilarDlls(_dirModel, subRef, ref similarDlls); if (similarDlls.Count < 1) { continue; } string destFilePath = Path.Combine(destDir, Path.GetFileName(similarDlls[0])); if (_copiedFiles.Contains(destFilePath)) { continue; } _copiedFiles.Add(destFilePath); File.Copy(similarDlls[0], destFilePath, true); if (strategy.DeepCopy) { int count = 0; this.CopySubRefDlls(similarDlls[0], destDir, dllRootDir, ref count); } if (strategy.CopyHideRefDlls && strategy.UseStrStrategy) { this.CopyHideRefDlls(dllRootDir, similarDlls[0], destDir, strategy); } } } if (strategy.CopyHideRefDlls && strategy.UseDirStrategy) { this.CopyHideRefFiles(dllRootDir, destDir, strategy); } this.Cursor = Cursors.Default; }