Beispiel #1
0
        public override int Execute()
        {
            SlnFile slnFile = SlnFileFactory.CreateFromFileOrDirectory(_fileOrDirectory);

            var relativeProjectPaths = _appliedCommand.Arguments.Select(p =>
                                                                        PathUtility.GetRelativePath(
                                                                            PathUtility.EnsureTrailingSlash(slnFile.BaseDirectory),
                                                                            Path.GetFullPath(p)))
                                       .ToList();

            bool slnChanged = false;

            foreach (var path in relativeProjectPaths)
            {
                slnChanged |= slnFile.RemoveProject(path);
            }

            slnFile.RemoveEmptyConfigurationSections();

            slnFile.RemoveEmptySolutionFolders();

            if (slnChanged)
            {
                slnFile.Write();
            }

            return(0);
        }
Beispiel #2
0
        public override int Execute()
        {
            SlnFile slnFile = SlnFileFactory.CreateFromFileOrDirectory(_fileOrDirectory);

            var baseDirectory        = PathUtility.EnsureTrailingSlash(slnFile.BaseDirectory);
            var relativeProjectPaths = _arguments.Select(p => {
                var fullPath = Path.GetFullPath(p);
                return(Path.GetRelativePath(
                           baseDirectory,
                           Directory.Exists(fullPath) ?
                           MsbuildProject.GetProjectFileFromDirectory(fullPath).FullName :
                           fullPath
                           ));
            });

            bool slnChanged = false;

            foreach (var path in relativeProjectPaths)
            {
                slnChanged |= slnFile.RemoveProject(path);
            }

            slnFile.RemoveEmptyConfigurationSections();

            slnFile.RemoveEmptySolutionFolders();

            if (slnChanged)
            {
                slnFile.Write();
            }

            return(0);
        }
Beispiel #3
0
        public override int Run(string fileOrDirectory)
        {
            SlnFile slnFile = SlnFileFactory.CreateFromFileOrDirectory(fileOrDirectory);

            if (RemainingArguments.Count == 0)
            {
                throw new GracefulException(CommonLocalizableStrings.SpecifyAtLeastOneProjectToRemove);
            }

            var relativeProjectPaths = RemainingArguments.Select((p) =>
                                                                 PathUtility.GetRelativePath(
                                                                     PathUtility.EnsureTrailingSlash(slnFile.BaseDirectory),
                                                                     Path.GetFullPath(p))).ToList();

            bool slnChanged = false;

            foreach (var path in relativeProjectPaths)
            {
                slnChanged |= slnFile.RemoveProject(path);
            }

            slnFile.RemoveEmptyConfigurationSections();

            slnFile.RemoveEmptySolutionFolders();

            if (slnChanged)
            {
                slnFile.Write();
            }

            return(0);
        }
Beispiel #4
0
        private void RemoveReferencesToMigratedFiles(SlnFile slnFile)
        {
            var solutionFolders = slnFile.Projects.GetProjectsByType(ProjectTypeGuids.SolutionFolderGuid);

            foreach (var solutionFolder in solutionFolders)
            {
                var solutionItems = solutionFolder.Sections.GetSection("SolutionItems");
                if (solutionItems != null && solutionItems.Properties.ContainsKey("global.json"))
                {
                    solutionItems.Properties.Remove("global.json");
                    if (solutionItems.IsEmpty)
                    {
                        solutionFolder.Sections.Remove(solutionItems);
                    }
                }
            }

            slnFile.RemoveEmptySolutionFolders();
        }