/// <summary> /// Creates and loads a new solution in the host process, optionally saving the existing solution if one exists. /// </summary> public void CreateSolution(string solutionName, bool saveExistingSolutionIfExists = false) { var dte = GetDTE(); if (dte.Solution.IsOpen) { CloseSolution(saveExistingSolutionIfExists); } var solutionPath = IntegrationHelper.CreateTemporaryPath(); var solutionFileName = Path.ChangeExtension(solutionName, ".sln"); IntegrationHelper.DeleteDirectoryRecursively(solutionPath); Directory.CreateDirectory(solutionPath); var solution = GetGlobalService <SVsSolution, IVsSolution>(); InvokeOnUIThread(cancellationToken => { ErrorHandler.ThrowOnFailure(solution.CreateSolution(solutionPath, solutionFileName, (uint)__VSCREATESOLUTIONFLAGS.CSF_SILENT)); ErrorHandler.ThrowOnFailure(solution.SaveSolutionElement((uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_ForceSave, null, 0)); }); _solution = (Solution2)dte.Solution; _fileName = Path.Combine(solutionPath, solutionFileName); }
/// <summary> /// Creates and loads a new solution in the host process, optionally saving the existing solution if one exists. /// </summary> public void CreateSolution(string solutionName, bool saveExistingSolutionIfExists = false) { var dte = GetDTE(); if (dte.Solution.IsOpen) { CloseSolution(saveExistingSolutionIfExists); } string solutionPath = IntegrationHelper.CreateTemporaryPath(); IntegrationHelper.DeleteDirectoryRecursively(solutionPath); dte.Solution.Create(solutionPath, solutionName); _solution = (Solution2)dte.Solution; _fileName = Path.Combine(solutionPath, $"{solutionName}.sln"); }