Example #1
0
        /// <summary>Creates and loads a new solution in the host process, optionally saving the existing solution if one exists.</summary>
        public Solution CreateSolution(string solutionName, bool saveExistingSolutionIfExists = false)
        {
            var dteSolution = IntegrationHelper.RetryRpcCall(() => _visualStudio.Dte.Solution);

            if (IntegrationHelper.RetryRpcCall(() => dteSolution.IsOpen))
            {
                CloseSolution(saveExistingSolutionIfExists);
            }

            var solutionPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            IntegrationHelper.DeleteDirectoryRecursively(solutionPath);

            IntegrationHelper.RetryRpcCall(() => dteSolution.Create(solutionPath, solutionName));
            _solution = new Solution((Solution2)(dteSolution), Path.Combine(solutionPath, $"{solutionName}.sln"));

            return(_solution);
        }