private IEnumerable<LibraryDependency> GetDependencies(NuspecReader nuspecReader, NuGetFramework targetFramework) { var dependencies = NuGetFrameworkUtility.GetNearest(nuspecReader.GetDependencyGroups(), targetFramework, item => item.TargetFramework); var frameworkAssemblies = NuGetFrameworkUtility.GetNearest(nuspecReader.GetFrameworkReferenceGroups(), targetFramework, item => item.TargetFramework); return GetDependencies(targetFramework, dependencies, frameworkAssemblies); }
/// <summary> /// A package is deemed to be a satellite package if it has a language property set, the id of the package is /// of the format [.*].[Language] /// and it has at least one dependency with an id that maps to the runtime package . /// </summary> private static async Task <SatellitePackageInfo> GetSatellitePackageInfoAsync( IAsyncPackageCoreReader packageReader, CancellationToken cancellationToken) { // A satellite package has the following properties: // 1) A package suffix that matches the package's language, with a dot preceding it // 2) A dependency on the package with the same Id minus the language suffix // 3) The dependency can be found by Id in the repository (as its path is needed for installation) // Example: foo.ja-jp, with a dependency on foo var nuspec = await packageReader.GetNuspecAsync(cancellationToken); var nuspecReader = new NuspecReader(nuspec); var packageId = nuspecReader.GetId(); var packageLanguage = nuspecReader.GetLanguage(); string localRuntimePackageId = null; PackageIdentity runtimePackageIdentity = null; if (!string.IsNullOrEmpty(packageLanguage) && packageId.EndsWith('.' + packageLanguage, StringComparison.OrdinalIgnoreCase)) { // The satellite pack's Id is of the format <Core-Package-Id>.<Language>. Extract the core package id using this. // Additionally satellite packages have a strict dependency on the core package localRuntimePackageId = packageId.Substring(0, packageId.Length - packageLanguage.Length - 1); foreach (var group in nuspecReader.GetDependencyGroups()) { foreach (var dependencyPackage in group.Packages) { if (dependencyPackage.Id.Equals(localRuntimePackageId, StringComparison.OrdinalIgnoreCase) && dependencyPackage.VersionRange != null && dependencyPackage.VersionRange.MaxVersion == dependencyPackage.VersionRange.MinVersion && dependencyPackage.VersionRange.IsMaxInclusive && dependencyPackage.VersionRange.IsMinInclusive) { var runtimePackageVersion = new NuGetVersion(dependencyPackage.VersionRange.MinVersion.ToNormalizedString()); runtimePackageIdentity = new PackageIdentity(dependencyPackage.Id, runtimePackageVersion); } } } } return(new SatellitePackageInfo(runtimePackageIdentity != null, packageLanguage, runtimePackageIdentity)); }
/// <summary> /// A package is deemed to be a satellite package if it has a language property set, the id of the package is /// of the format [.*].[Language] /// and it has at least one dependency with an id that maps to the runtime package . /// </summary> public static bool IsSatellitePackage(NuspecReader nuspecReader, out PackageIdentity runtimePackageIdentity, out string packageLanguage) { // A satellite package has the following properties: // 1) A package suffix that matches the package's language, with a dot preceding it // 2) A dependency on the package with the same Id minus the language suffix // 3) The dependency can be found by Id in the repository (as its path is needed for installation) // Example: foo.ja-jp, with a dependency on foo var packageId = nuspecReader.GetId(); packageLanguage = nuspecReader.GetLanguage(); if (!String.IsNullOrEmpty(packageLanguage) && packageId.EndsWith('.' + packageLanguage, StringComparison.OrdinalIgnoreCase)) { // The satellite pack's Id is of the format <Core-Package-Id>.<Language>. Extract the core package id using this. // Additionally satellite packages have a strict dependency on the core package var localruntimePackageId = packageId.Substring(0, packageId.Length - packageLanguage.Length - 1); foreach (var group in nuspecReader.GetDependencyGroups()) { foreach (var dependencyPackage in group.Packages) { if (dependencyPackage.Id.Equals(localruntimePackageId, StringComparison.OrdinalIgnoreCase) && dependencyPackage.VersionRange != null && dependencyPackage.VersionRange.MaxVersion == dependencyPackage.VersionRange.MinVersion && dependencyPackage.VersionRange.IsMaxInclusive && dependencyPackage.VersionRange.IsMinInclusive) { var runtimePackageVersion = new NuGetVersion(dependencyPackage.VersionRange.MinVersion.ToString()); runtimePackageIdentity = new PackageIdentity(dependencyPackage.Id, runtimePackageVersion); return(true); } } } } runtimePackageIdentity = null; return(false); }
/// <summary> /// A package is deemed to be a satellite package if it has a language property set, the id of the package is /// of the format [.*].[Language] /// and it has at least one dependency with an id that maps to the runtime package . /// </summary> public static bool IsSatellitePackage(NuspecReader nuspecReader, out PackageIdentity runtimePackageIdentity, out string packageLanguage) { // A satellite package has the following properties: // 1) A package suffix that matches the package's language, with a dot preceding it // 2) A dependency on the package with the same Id minus the language suffix // 3) The dependency can be found by Id in the repository (as its path is needed for installation) // Example: foo.ja-jp, with a dependency on foo var packageId = nuspecReader.GetId(); packageLanguage = nuspecReader.GetLanguage(); if (!String.IsNullOrEmpty(packageLanguage) && packageId.EndsWith('.' + packageLanguage, StringComparison.OrdinalIgnoreCase)) { // The satellite pack's Id is of the format <Core-Package-Id>.<Language>. Extract the core package id using this. // Additionally satellite packages have a strict dependency on the core package var localruntimePackageId = packageId.Substring(0, packageId.Length - packageLanguage.Length - 1); foreach (var group in nuspecReader.GetDependencyGroups()) { foreach (var dependencyPackage in group.Packages) { if (dependencyPackage.Id.Equals(localruntimePackageId, StringComparison.OrdinalIgnoreCase) && dependencyPackage.VersionRange != null && dependencyPackage.VersionRange.MaxVersion == dependencyPackage.VersionRange.MinVersion && dependencyPackage.VersionRange.IsMaxInclusive && dependencyPackage.VersionRange.IsMinInclusive) { var runtimePackageVersion = new NuGetVersion(dependencyPackage.VersionRange.MinVersion.ToString()); runtimePackageIdentity = new PackageIdentity(dependencyPackage.Id, runtimePackageVersion); return true; } } } } runtimePackageIdentity = null; return false; }
public static PackageMetadata FromNuspecReader(NuspecReader nuspecReader) { return new PackageMetadata( nuspecReader.GetMetadata().ToDictionary(kvp => kvp.Key, kvp => kvp.Value), nuspecReader.GetDependencyGroups(), nuspecReader.GetFrameworkReferenceGroups() ); }
public static NuGetDependencyInfo GetDependencyInfo(FileInfo nupkgPath) { if (!nupkgPath.Exists) { throw new FileNotFoundException(nupkgPath.FullName); } using (var stream =nupkgPath.OpenRead()) { ZipFileSystem zip = new ZipFileSystem(stream); using (PackageReader packageReader = new PackageReader(zip)) { using (var nuspecStream = packageReader.GetNuspec()) { NuspecReader reader = new NuspecReader(nuspecStream); NuGetPackageId package = CreateIdentity(reader, nupkgPath.FullName); List<NuGetDependencyGroup> dependencyGroups = new List<NuGetDependencyGroup>(); foreach (var depGroup in reader.GetDependencyGroups()) { FrameworkName framework = Utilities.GetFrameworkName(depGroup.TargetFramework); NuGetDependency[] dependencies = depGroup.Packages.Select(d => new NuGetDependency(d.Id, VersionRange.Parse(d.VersionRange))).ToArray(); dependencyGroups.Add(new NuGetDependencyGroup(framework, dependencies)); } return new NuGetDependencyInfo(package, dependencyGroups); } } } }
protected static FindPackageByIdDependencyInfo GetDependencyInfo(NuspecReader reader) { return new FindPackageByIdDependencyInfo( reader.GetDependencyGroups(), reader.GetFrameworkReferenceGroups()); }