static VersionRange GetVersionRange(PackageReferenceInfo package) { if (string.IsNullOrEmpty(package.VersionRange)) { return(null); } return(VersionRange.Parse(package.VersionRange)); }
static PackageReference CreatePackageReference(PackageReferenceInfo package) { return(new PackageReference( new PackageIdentity(package.Id, new NuGetVersion(package.Version)), NuGetFramework.Parse(package.TargetFramework), package.IsUserInstalled, package.IsDevelopmentDependency, package.RequireReinstallation, GetVersionRange(package) )); }
private async Task LoadDependenciesAsync(PackageReferenceInfo entry, List <PackageReferenceInfo> packages, List <Task> tasks, IConsoleHost host) { var resource = await CreatePackageMetadataResourceAsync(); try { var identity = new PackageIdentity(entry.Name, NuGetVersion.Parse(entry.Version)); var result = await resource.GetMetadataAsync(identity, new NullLogger(), CancellationToken.None); if (result != null) { entry.LicenseUri = result.LicenseUrl; if (IncludeTransitiveDependencies) { foreach (var dependentPackage in result.DependencySets.SelectMany(s => s.Packages)) { lock (packages) { if (dependentPackage.Id != "NETStandard.Library" && (!ExcludeSystem || !dependentPackage.Id.StartsWith("System.")) && (!ExcludeMicrosoft || !dependentPackage.Id.StartsWith("Microsoft."))) { var subEntry = packages.SingleOrDefault(p => p.Name == dependentPackage.Id && p.Version == dependentPackage.VersionRange.MinVersion.ToFullString()); if (subEntry == null) { var package = new PackageReferenceInfo { Name = dependentPackage.Id, Version = dependentPackage.VersionRange.MinVersion.ToFullString() }; packages.Add(package); tasks.Add(LoadDependenciesAsync(package, packages, tasks, host)); } else { subEntry.Count++; } } } } } } host.WriteMessage("."); } catch (Exception e) { host.WriteError(e + "\n"); } }
private void LoadProjects(IConsoleHost host, List <PackageReferenceInfo> packages) { host.WriteMessage($"Loading projects "); var globalProperties = TryGetGlobalProperties(); foreach (var projectPath in GetProjectPaths()) { try { using (var projectInformation = ProjectExtensions.LoadProject(projectPath, globalProperties)) { foreach (var item in projectInformation.Project.Items.Where(i => i.ItemType == "PackageReference").ToList()) { var packageName = item.EvaluatedInclude; var packageVersion = item.Metadata.SingleOrDefault(m => m.Name == "Version")?.EvaluatedValue ?? "Latest"; if (packageName != "NETStandard.Library" && (!ExcludeSystem || !packageName.StartsWith("System.")) && (!ExcludeMicrosoft || !packageName.StartsWith("Microsoft."))) { var entry = packages.SingleOrDefault(p => p.Name == packageName && p.Version == packageVersion); if (entry == null) { entry = new PackageReferenceInfo { Name = packageName, Version = packageVersion, Type = "t" }; packages.Add(entry); } else { entry.Count++; } host.WriteMessage("."); } } } } catch (Exception e) { host.WriteError(e + "\n"); } } host.WriteMessage($"\n"); }
private bool IsAssemblyFromPackage(ParsedPath pathHint, PackageReferenceInfo package) { var ignoreCase = StringComparison.InvariantCultureIgnoreCase; var partText = $"{package.PackageId}.{package.Version}"; var partIndex = pathHint.Parts .TakeWhile(p => !p.Equals(partText, ignoreCase)) .Count(); if (partIndex > 0 && partIndex < pathHint.Parts.Count - 1) { return( pathHint.Parts[partIndex - 1].Equals("packages", ignoreCase) && pathHint.Parts[partIndex + 1].Equals("lib", ignoreCase)); } return(false); }
private static async Task LoadLicenseAsync(HttpClient httpClient, PackageReferenceInfo entry, IConsoleHost host) { try { if (entry.LicenseUri != null) { var licenseUri = entry.LicenseUri?.ToString(); if (licenseUri?.Contains("apache.org") == true) { entry.License = "Apache"; } if (licenseUri?.Contains("/LGPL-") == true) { entry.License = "LGPL"; } if (licenseUri?.Contains("/GPL-") == true) { entry.License = "GPL"; } else { var license = await httpClient.GetStringAsync(entry.LicenseUri); if (license.Contains("www.apache.org")) { entry.License = "Apache"; } else if (license.Contains("Lesser General Public License")) { entry.License = "LGPL"; } else if (license.Contains("General Public License")) { entry.License = "GPL"; } else { var n = ""; n = string.IsNullOrWhiteSpace(n) ? Regex.Matches(license, "^\\s*([^><*]{1,20}[a-zA-Z] License)", RegexOptions.Multiline) .OfType <Match>().FirstOrDefault(m => !m.Groups[1].Value.Contains("the License"))?.Groups[1].Value : n; n = string.IsNullOrWhiteSpace(n) ? Regex.Matches(license, ">\\s*([^><*]{1,20}[a-zA-Z] License)", RegexOptions.Multiline) .OfType <Match>().FirstOrDefault(m => !m.Groups[1].Value.Contains("the License"))?.Groups[1].Value : n; n = string.IsNullOrWhiteSpace(n) ? Regex.Matches(license, "\n\\s*([^><*]{1,20}[a-zA-Z] License)", RegexOptions.Multiline) .OfType <Match>().FirstOrDefault(m => !m.Groups[1].Value.Contains("the License"))?.Groups[1].Value : n; n = n ?? ""; entry.License = n .Trim('\r', '\n', ' ', '?') .Replace("The ", string.Empty) .Replace(" License", string.Empty); } } host.WriteMessage("."); } } catch (Exception e) { host.WriteError(e + "\n"); } }