private static bool TargetFrameworkName_CompatibilityTest(object criteria, object available) { var criteriaFrameworkName = criteria as NuGetFramework; var availableFrameworkName = available as NuGetFramework; if (criteriaFrameworkName != null && availableFrameworkName != null) { // We only consider 'any' matches when the criteria explicitly asks for them if (criteriaFrameworkName.IsAny && availableFrameworkName.IsAny) { return(true); } else if (Object.Equals(AnyFramework.AnyFramework, availableFrameworkName)) { // If the convention does not contain a TxM it will use AnyFramework, this is // always compatible with other frameworks. return(true); } else if (criteriaFrameworkName.IsAny || availableFrameworkName.IsAny) { // Otherwise, ignore 'any' framework values return(false); } return(NuGetFrameworkUtility.IsCompatibleWithFallbackCheck(criteriaFrameworkName, availableFrameworkName)); } return(false); }
private static bool TargetFrameworkName_CompatibilityTest(object criteria, object available) { var criteriaFrameworkName = criteria as NuGetFramework; var availableFrameworkName = available as NuGetFramework; if (criteriaFrameworkName != null && availableFrameworkName != null) { // We only consider 'any' matches when the criteria explicitly asks for them if (criteriaFrameworkName.IsAny && availableFrameworkName.IsAny) { return(true); } else if (criteriaFrameworkName.IsAny || availableFrameworkName.IsAny) { // Otherwise, ignore 'any' framework values return(false); } return(NuGetFrameworkUtility.IsCompatibleWithFallbackCheck(criteriaFrameworkName, availableFrameworkName)); } return(false); }
/// <summary> /// Gets the list of packages to install along with there dependencies /// </summary> /// <param name="repository">The package repository</param> /// <param name="seederConfiguration">The seeder configuration</param> /// <returns>The list of packages</returns> private static async Task <IEnumerable <PackageIdentity> > GetPackagesToInstall( IPackageRepository repository, SeederConfiguration seederConfiguration) { // TODO: extract to helper method along with Configuration extensions var supportedFramework = NuGetFramework.ParseFrameworkName( PackageRepositoryExtensions.CurrentRuntime, DefaultFrameworkNameProvider.Instance); var packageTasks = seederConfiguration.RequiredPackages.Select( async packageName => { var package = await repository.GetAsync(packageName); if (package == null) { throw new PackageNotFoundException(packageName); } return(package); }); var packagesToInstall = (await Task.WhenAll(packageTasks)).ToDictionary(p => p.Identity.Id); var queue = new Queue <IPackageSearchMetadata>(packagesToInstall.Values); while (queue.Count > 0) { var package = queue.Dequeue(); var dependencySet = NuGetFrameworkUtility.GetNearest(package.DependencySets, supportedFramework); if (dependencySet == null || !NuGetFrameworkUtility.IsCompatibleWithFallbackCheck( supportedFramework, dependencySet.TargetFramework)) { continue; } foreach (var dependency in dependencySet.Packages) { IPackageSearchMetadata packageToInstall; if (!packagesToInstall.TryGetValue(dependency.Id, out packageToInstall)) { packageToInstall = await repository.GetAsync(dependency.Id); if (packageToInstall == null) { throw new PackageNotFoundException(dependency.Id); } packagesToInstall.Add(dependency.Id, packageToInstall); if (queue.All(p => p.Identity.Id != packageToInstall.Identity.Id)) { queue.Enqueue(packageToInstall); } } } } return(packagesToInstall.Values.Select(p => p.Identity)); }
private static IEnumerable <string> EnumerateFiles(string path, string frameworkFolderName, string searchPattern, SearchOption searchOption, out string frameworkPath) { if (frameworkFolderName is null) { var targetFrameworkCount = Directory.EnumerateDirectories(path).Count(); if (targetFrameworkCount > 1) { throw new ArgumentNullException(nameof(frameworkFolderName)); } else if (targetFrameworkCount == 0) { frameworkPath = null; return(Array.Empty <string>()); } else { frameworkFolderName = Directory.EnumerateDirectories(path).Single(); } } if (!Directory.Exists(path)) { frameworkPath = null; return(Array.Empty <string>()); } frameworkPath = Path.Combine(path, frameworkFolderName ?? Directory.EnumerateDirectories(path).Single()); if (!Directory.Exists(frameworkPath)) { var targetFramework = NuGetFramework.Parse(frameworkFolderName); var compatibleFrameworks = Directory.EnumerateDirectories(path) .Where(folder => NuGetFrameworkUtility.IsCompatibleWithFallbackCheck(targetFramework, NuGetFramework.ParseFolder(new DirectoryInfo(folder).Name))); // TODO: how to select best match framework? frameworkPath = compatibleFrameworks.FirstOrDefault(); if (frameworkPath is null) { // Ignore folders that contain no .dll (or .cs) files (empty lib folders usually have a file called "_._" in it). compatibleFrameworks = Directory.EnumerateDirectories(path) .Where(folder => NuGetFrameworkUtility.IsCompatibleWithFallbackCheck(NuGetFramework.ParseFolder(new DirectoryInfo(folder).Name), targetFramework)) .Where(folder => Directory.EnumerateFiles(folder, searchPattern, SearchOption.AllDirectories).FirstOrDefault() != null); // TODO: how to select best match framework? frameworkPath = compatibleFrameworks.FirstOrDefault(); if (frameworkPath is null) { return(Array.Empty <string>()); } } } return(Directory.EnumerateFiles(frameworkPath, searchPattern, searchOption)); }
private static PackageDependencyGroup GetDependencyGroup(PackageIdentity package, NuGetFramework targetFramework) { var nuspecFile = Path.Combine(_globalPackagesPath, package.Id, package.Version.ToNormalizedString(), $"{package.Id}.nuspec"); if (!NuGet.Packaging.PackageHelper.IsNuspec(nuspecFile)) { throw new PackageException($"Could not locate the .nuspec file for package: {package}"); } var reader = new NuspecReader(nuspecFile); var dependencyGroups = reader.GetDependencyGroups(); if (dependencyGroups.FirstOrDefault() != null) { var compatibleGroups = dependencyGroups.Where(dependencyGroup => NuGetFrameworkUtility.IsCompatibleWithFallbackCheck(targetFramework, dependencyGroup.TargetFramework)); // TODO: how to select best match framework? return(compatibleGroups.First()); } return(null); }
private static IEnumerable <Package> GetUpdates( IEnumerable <Package> packages, ILookup <string, Tuple <NuGetVersion, VersionRange> > versionLookup, IEnumerable <NuGetFramework> targetFrameworkValues, bool includeAllVersions, string semVerLevel) { var isSemVerLevelCompliant = SemVerLevelKey.IsPackageCompliantWithSemVerLevelPredicate(semVerLevel).Compile(); var updates = from p in packages.AsEnumerable() let version = NuGetVersion.Parse(p.Version) where isSemVerLevelCompliant(p) && versionLookup[p.PackageRegistration.Id].Any(versionTuple => { NuGetVersion clientVersion = versionTuple.Item1; var supportedPackageFrameworks = p.SupportedFrameworks.Select(f => f.FrameworkName); VersionRange versionConstraint = versionTuple.Item2; return(version > clientVersion && (targetFrameworkValues == null || !supportedPackageFrameworks.Any() || targetFrameworkValues.Any(s => supportedPackageFrameworks.Any(supported => NuGetFrameworkUtility.IsCompatibleWithFallbackCheck(s, supported)))) && (versionConstraint == null || versionConstraint.Satisfies(version))); }) select p; if (!includeAllVersions) { updates = updates.GroupBy(p => p.PackageRegistration.Id) .Select(g => g.OrderByDescending(p => NuGetVersion.Parse(p.Version)).First()); } return(updates); }