public List <ProjectInfo> GetAllDependenciesRequiredForProject(List <string> codeRootsFolders, List <string> excludeProjectFolders, string projectName,
                                                                       bool includeTestProjects, IEnumerable <string> projectExclusionList)
        {
            var projects = codeRootsFolders.Where(Directory.Exists).SelectMany(CsProjHelpers.GetAllProjects)
                           .Where(x => !projectExclusionList.Any(x.Contains))
                           .Where(x => !excludeProjectFolders.Any(x.Contains))
                           .Select(x => new ProjectInfo
            {
                ProjectName       = x,
                PackageName       = CsProjHelpers.GetPackageNameFromCsProj(x),
                PackageReferences = CsProjHelpers.ReadAllPackageReferencesFromCsProjFile(x),
                ProjectReferences = CsProjHelpers.ReadAllProjectReferencesFromCsProjFile(x),
            }).ToList();

            // Filter package references by projects we know about (ie. not 3rd party ones)
            foreach (var project in projects)
            {
                project.PackageReferences = project.PackageReferences.Where(d => projects.Any(p => p.PackageName.ToLower() == d.ToLower())).ToList();
            }

            var projectLookup = projects.ToDictionary(k => k.PackageName.ToLower(), v => v);

            var results = new List <ProjectInfo>();

            if (!projectLookup.ContainsKey(projectName.ToLower()))
            {
                return(results); // This suggests that the 'coderootfolder' specified by the user doesn't contain a git repo with the selected project that they want to munge
            }
            // Recursively scan through all the projects, building up a list of non-3rd-party dependencies
            GetDependenciesRecursively(projectLookup, projectName, includeTestProjects, results);

            return(results.Distinct().OrderBy(x => x.PackageName).ToList());
        }
Esempio n. 2
0
        public static void Convert(List <ProjectInfo> allProjectsInSolution, string csprojFilename)
        {
            var packageReferences = CsProjHelpers.ReadAllPackageReferencesFromCsProjFile(csprojFilename);

            var packageReferencesToConvert = packageReferences
                                             .Join(allProjectsInSolution, p => p.ToLower(), pis => pis.PackageName.ToLower(),
                                                   (pr, pis) => new { ProjectReference = pr, ProjectPath = pis.MungeProjectName })
                                             .ToDictionary(k => k.ProjectReference.ToLower(), v => v.ProjectPath);

            var csProjAbsPath = Path.GetFullPath(csprojFilename);

            File.WriteAllText(csprojFilename,
                              CsProjHelpers.ChangePackageReferencesToProjectReferences(File.ReadAllText(csProjAbsPath), packageReferencesToConvert, csProjAbsPath));
        }