private void btnOK_Click(object sender, EventArgs e) { try { this.Cursor = Cursors.WaitCursor; Solution3 sol3 = _app.Solution as Solution3; if (sol3 == null || string.IsNullOrEmpty(sol3.FileName)) { MsgBox.ShowTip("请先打开已有解决方案或者新建一个解决方案"); return; } List <Project> existProjs = ProjectUtility.GetAllProjects(_app); for (int i = 0; i < this.treeView1.Nodes.Count; i++) { TreeNode rootNode = this.treeView1.Nodes[i]; if (rootNode.Checked && rootNode.Nodes.Count > 0) { string foldName = rootNode.Tag as string; bool isExistFolder = false; for (int j = 1; j < sol3.Projects.Count; j++) { Project proj = sol3.Projects.Item(j); if (proj.Kind != ProjectKinds.vsProjectKindSolutionFolder) { continue; } if (sol3.Projects.Item(j).Name.Equals(foldName, StringComparison.CurrentCultureIgnoreCase)) { isExistFolder = true; break; } } if (isExistFolder == false) { Project solFolder = sol3.AddSolutionFolder(rootNode.Tag as string); } for (int j = 0; j < rootNode.Nodes.Count; j++) { if (rootNode.Nodes[j].Checked) { string projPath = rootNode.Nodes[j].Tag as string; bool isExist = false; for (int k = 0; k < existProjs.Count; k++) { if (existProjs[k].FileName.Equals(projPath, StringComparison.CurrentCultureIgnoreCase)) { isExist = true; break; } } if (isExist == false) { Project proj = sol3.AddFromFile(projPath, false); } else { MsgBox.ShowTip(Path.GetFileNameWithoutExtension(projPath) + "已经加载"); } } } } else { for (int j = 0; j < rootNode.Nodes.Count; j++) { if (rootNode.Nodes[j].Checked) { string projPath = rootNode.Nodes[j].Tag as string; bool isExist = false; for (int k = 0; k < existProjs.Count; k++) { if (existProjs[k].FileName.Equals(projPath, StringComparison.CurrentCultureIgnoreCase)) { isExist = true; break; } } if (isExist == false) { Project proj = sol3.AddFromFile(projPath, false); } else { MsgBox.ShowTip(Path.GetFileNameWithoutExtension(projPath) + "已经加载"); } } } } } this.DialogResult = System.Windows.Forms.DialogResult.OK; } catch (Exception ex) { MsgBox.ShowTip(ex.Message); } finally { this.Cursor = Cursors.Default; } }
private void btnOK_Click(object sender, EventArgs e) { try { this.Cursor = Cursors.WaitCursor; Solution3 sol3 = _app.Solution as Solution3; if (sol3 == null || string.IsNullOrEmpty(sol3.FileName)) { MsgBox.ShowTip("请先打开已有解决方案或者新建一个解决方案"); return; } string saveDir = this.txtSaveDir.Text.Trim(); if (string.IsNullOrEmpty(saveDir) || Directory.Exists(saveDir) == false) { MsgBox.ShowTip("请选择项目保存位置"); return; } string rootDir = this.txtRootDir.Text.Trim(); rootDir = rootDir.TrimEnd('.'); if (string.IsNullOrEmpty(rootDir)) { MsgBox.ShowTip("根名字空间不能为空"); return; } bool isExistFolder = false; for (int j = 1; j < sol3.Projects.Count; j++) { Project proj = sol3.Projects.Item(j); if (proj.Kind != ProjectKinds.vsProjectKindSolutionFolder) { continue; } if (sol3.Projects.Item(j).Name.Equals(rootDir, StringComparison.CurrentCultureIgnoreCase)) { isExistFolder = true; break; } } if (isExistFolder == false) { Project solFolder = sol3.AddSolutionFolder(rootDir); } List <Project> existProjs = ProjectUtility.GetAllProjects(_app); for (int i = 0; i < this.richTextBox1.Lines.Length; i++) { string subDir = this.richTextBox1.Lines[i].Trim(); subDir = subDir.TrimStart('.').TrimEnd('.'); if (string.IsNullOrEmpty(subDir)) { continue; } subDir = rootDir + "." + subDir; string projPath = Path.Combine(saveDir, subDir + "\\" + subDir + ".csproj"); bool isExist = false; for (int k = 0; k < existProjs.Count; k++) { if (existProjs[k].FileName.Equals(projPath, StringComparison.CurrentCultureIgnoreCase)) { isExist = true; break; } } if (isExist == false) { if (File.Exists(projPath)) { DialogResult rlt = MsgBox.ShowOkCancel("项目保存位置下已经存在:" + subDir + ",是否需要加载?"); if (rlt == DialogResult.OK) { sol3.AddFromFile(projPath, false); } continue; } string templatePath = sol3.GetProjectTemplate("ClassLibrary.zip", "CSharp"); Project proj = sol3.AddFromTemplate(templatePath, Path.Combine(saveDir, subDir), subDir, true); } else { MsgBox.ShowTip(subDir + "已经存在"); } } this.DialogResult = System.Windows.Forms.DialogResult.OK; } catch (Exception ex) { MsgBox.ShowTip(ex.Message); } finally { this.Cursor = Cursors.Default; } }