public int Execute(NugetConsolidateCommands commands) { var path = Directory.GetCurrentDirectory(); var files = Directory.GetFiles(path, "packages.config", SearchOption.AllDirectories); var res = LocalExecute(commands, files); if (commands.Check) { if (!commands.Consolidate) { foreach (var pack in NugetPackages) { WriteVersionsAndProjects(commands, pack); } } else { foreach (var pack in NugetPackages.Where(o => o.Versions.Count > 1)) { WriteVersionsAndProjects(commands, pack); } } } return(res); }
private static void WriteVersionsAndProjects(NugetConsolidateCommands commands, NugetPackage pack) { Console.WriteLine(pack.Name); foreach (var version in pack.Versions) { Console.WriteLine($" {version.Version}"); if (!commands.Short) { foreach (var project in version.Projects) { Console.WriteLine($" {project.Name}"); } } } }
public int LocalExecute(NugetConsolidateCommands command, IEnumerable <string> files) { foreach (var packageconfigFile in files) { var content = File.ReadAllLines(packageconfigFile); var csprojFileName = FindCsProjFileName(packageconfigFile); foreach (var line in content.Where(l => l.Contains("<package "))) { var parts = line.Trim().Split(' ').ToList(); if (parts.Count < 3) { continue; } var id = parts[1].Split('=')[1].Trim('"'); var version = parts[2].Split('=')[1].Trim('"'); Update(csprojFileName, id, version); } } return(0); }