/// <summary> /// Closes the solution: cancels build, clears solution data, fires the SolutionClosing and SolutionClosed events. /// <remarks> /// Before invoking this method, one should check if the closing was canceled (<see cref="IsClosingCanceled"/>), /// save solution and project data (e.g. files, bookmarks), then invoke CloseSolution(). /// </remarks> /// </summary> internal static void CloseSolution() { // If a build is running, cancel it. // If we would let a build run but unload the MSBuild projects, the next project.StartBuild call // could cause an exception. BuildEngine.CancelGuiBuild(); if (openSolution != null) { CurrentProject = null; OnSolutionClosing(new SolutionEventArgs(openSolution)); openSolution.Dispose(); openSolution = null; ParserService.OnSolutionClosed(); OnSolutionClosed(EventArgs.Empty); CommandManager.InvalidateRequerySuggested(); } }
public ISolution LoadSolutionFile(FileName fileName, IProgressMonitor progress) { if (fileName == null) throw new ArgumentNullException("fileName"); if (progress == null) throw new ArgumentNullException("progress"); if (fileName.IsRelative) throw new ArgumentException("Path must be rooted!"); Solution solution = new Solution(fileName, new ProjectChangeWatcher(fileName), SD.FileService); bool ok = false; try { using (var loader = new SolutionLoader(fileName)) { loader.ReadSolution(solution, progress); } ok = true; } finally { if (!ok) solution.Dispose(); } return solution; }
public string CreateSolution(ProjectCreateInformation projectCreateInformation, string defaultLanguage) { string oldSolutionPath = projectCreateInformation.SolutionPath; string oldProjectPath = projectCreateInformation.ProjectBasePath; if (relativeDirectory != null && relativeDirectory.Length > 0 && relativeDirectory != ".") { projectCreateInformation.SolutionPath = Path.Combine(projectCreateInformation.SolutionPath, relativeDirectory); projectCreateInformation.ProjectBasePath = Path.Combine(projectCreateInformation.SolutionPath, relativeDirectory); if (!Directory.Exists(projectCreateInformation.SolutionPath)) { Directory.CreateDirectory(projectCreateInformation.SolutionPath); } if (!Directory.Exists(projectCreateInformation.ProjectBasePath)) { Directory.CreateDirectory(projectCreateInformation.ProjectBasePath); } } projectCreateInformation.SolutionPath = oldSolutionPath; projectCreateInformation.ProjectBasePath = oldProjectPath; string newSolutionName = StringParser.Parse(name, new StringTagPair("ProjectName", projectCreateInformation.SolutionName)); string solutionLocation = Path.Combine(projectCreateInformation.SolutionPath, newSolutionName + ".sln"); Solution newSolution = new Solution(new ProjectChangeWatcher(solutionLocation)); projectCreateInformation.Solution = newSolution; newSolution.Name = newSolutionName; if (!mainFolder.AddContents(newSolution, projectCreateInformation, defaultLanguage, newSolution)) { newSolution.Dispose(); return null; } // Save solution if (File.Exists(solutionLocation)) { string question = StringParser.Parse("${res:ICSharpCode.SharpDevelop.Internal.Templates.CombineDescriptor.OverwriteProjectQuestion}", new StringTagPair("combineLocation", solutionLocation)); if (MessageService.AskQuestion(question)) { newSolution.Save(solutionLocation); } } else { newSolution.Save(solutionLocation); } ProjectService.OnSolutionCreated(new SolutionEventArgs(newSolution)); newSolution.Dispose(); return solutionLocation; }
public string CreateSolution(ProjectCreateInformation projectCreateInformation, string defaultLanguage) { Solution newSolution = new Solution(); projectCreateInformation.Solution = newSolution; string newCombineName = StringParser.Parse(name, new string[,] { {"ProjectName", projectCreateInformation.ProjectName} }); newSolution.Name = newCombineName; string oldCombinePath = projectCreateInformation.SolutionPath; string oldProjectPath = projectCreateInformation.ProjectBasePath; if (relativeDirectory != null && relativeDirectory.Length > 0 && relativeDirectory != ".") { projectCreateInformation.SolutionPath = Path.Combine(projectCreateInformation.SolutionPath, relativeDirectory); projectCreateInformation.ProjectBasePath = Path.Combine(projectCreateInformation.SolutionPath, relativeDirectory); if (!Directory.Exists(projectCreateInformation.SolutionPath)) { Directory.CreateDirectory(projectCreateInformation.SolutionPath); } if (!Directory.Exists(projectCreateInformation.ProjectBasePath)) { Directory.CreateDirectory(projectCreateInformation.ProjectBasePath); } } projectCreateInformation.SolutionPath = oldCombinePath; projectCreateInformation.ProjectBasePath = oldProjectPath; if (!mainFolder.AddContents(newSolution, projectCreateInformation, defaultLanguage, newSolution)) { newSolution.Dispose(); return null; } string combineLocation = Path.Combine(projectCreateInformation.SolutionPath, newCombineName + ".sln"); // Save combine if (File.Exists(combineLocation)) { StringParser.Properties["combineLocation"] = combineLocation; if (MessageService.AskQuestion("${res:ICSharpCode.SharpDevelop.Internal.Templates.CombineDescriptor.OverwriteProjectQuestion}")) { newSolution.Save(combineLocation); } } else { newSolution.Save(combineLocation); } newSolution.Dispose(); return combineLocation; }