Beispiel #1
0
        public void CloseAndDeleteOpenSolution()
        {
            IntegrationHelper.RetryDteCall(() => _dte.Documents.CloseAll(EnvDTE.vsSaveChanges.vsSaveChangesNo));

            if (IntegrationHelper.RetryDteCall(() => _dte.Solution) != null)
            {
                var directoriesToDelete = IntegrationHelper.RetryDteCall(() =>
                {
                    var directoryList = new List <string>();

                    // Save the full path to each project in the solution. This is so we can cleanup any folders after the solution is closed.
                    foreach (EnvDTE.Project project in _dte.Solution.Projects)
                    {
                        directoryList.Add(Path.GetDirectoryName(project.FullName));
                    }

                    // Save the full path to the solution. This is so we can cleanup any folders after the solution is closed.
                    // The solution might be zero-impact and thus has no name, so deal with that
                    if (!string.IsNullOrEmpty(_dte.Solution.FullName))
                    {
                        directoryList.Add(Path.GetDirectoryName(_dte.Solution.FullName));
                    }

                    return(directoryList);
                });

                IntegrationHelper.RetryDteCall(() => _dte.Solution.Close(SaveFirst: false));

                foreach (var directoryToDelete in directoriesToDelete)
                {
                    IntegrationHelper.TryDeleteDirectoryRecursively(directoryToDelete);
                }
            }
        }