/// <summary> /// Process a packages.json file to enrich metadata /// </summary> /// <param name="fi">FileInfo</param> static void Process(FileInfo fi, Models.NgccOptions opts) { XElement doc = XElement.Load(fi.FullName); IEnumerable <XElement> itemGroups = from el in doc.Elements() where el.Name == "ItemGroup" select el; foreach (var ig in itemGroups) { IEnumerable <XElement> packages = from pr in ig.Elements() where pr.Name == "PackageReference" select pr; foreach (var pk in packages) { var dep = pk.Attribute("Include").Value; var ver = string.Empty; if (pk.Attribute("Version") != null) { ver = pk.Attribute("Version").Value; } string latest = string.Empty; if (!NuGetVersionList.ContainsKey(dep)) { latest = LastVersion(dep); if (!string.IsNullOrEmpty(latest)) { NuGetVersionList.Add(dep, latest); } } else { latest = NuGetVersionList[dep]; } var ngi = new Models.NugetInfo() { Id = dep, Version = ver, LatestVersion = latest, ProjectFile = fi.FullName.Replace(opts.Folder, string.Empty) }; if (opts.Verbose) { Console.WriteLine($"{ngi}"); } if ((!opts.ExcludeCurrent) || string.IsNullOrWhiteSpace(ngi.LatestVersion) || (ngi.Version != ngi.LatestVersion)) { info.Add(ngi); } } } }
/// <summary> /// Find Packages Files /// </summary> /// <param name="dirInfo">DirectoryInfo</param> static void FindPackages(DirectoryInfo dirInfo, Models.NgccOptions opts) { foreach (var fi in dirInfo.GetFiles("*.csproj", SearchOption.TopDirectoryOnly)) { if (opts.Verbose) { Console.WriteLine($"FindPackages({fi.FullName})"); } Process(fi, opts); } }
/// <summary> /// Recursive Traverse /// </summary> /// <param name="dirInfo">DirectoryInfo</param> static void Traverse(DirectoryInfo dirInfo, Models.NgccOptions opts) { foreach (var di in dirInfo.GetDirectories()) { if (opts.Verbose) { Console.WriteLine($"Traverse({di.FullName})"); } FindPackages(di, opts); Traverse(di, opts); } }