public static IPackage FindPackage(this IPackageRepository repository, string packageId, SemanticVersion version, IPackageConstraintProvider constraintProvider, bool allowPrereleaseVersions, bool allowUnlisted) { if (repository == null) { throw new ArgumentNullException("repository"); } if (packageId == null) { throw new ArgumentNullException("packageId"); } if (version != null) { allowUnlisted = true; } else if (!allowUnlisted && ((constraintProvider == null) || ReferenceEquals(constraintProvider, NullConstraintProvider.Instance))) { IPackage package; ILatestPackageLookup lookup2 = repository as ILatestPackageLookup; if ((lookup2 != null) && lookup2.TryFindLatestPackageById(packageId, allowPrereleaseVersions, out package)) { return(package); } } IPackageLookup lookup = repository as IPackageLookup; if ((lookup != null) && (version != null)) { return(lookup.FindPackage(packageId, version)); } IEnumerable <IPackage> packages = from p in repository.FindPackagesById(packageId).ToList <IPackage>() orderby p.Version descending select p; if (!allowUnlisted) { packages = Enumerable.Where <IPackage>(packages, new Func <IPackage, bool>(PackageExtensions.IsListed)); } if (version != null) { packages = from p in packages where p.Version == version select p; } else if (constraintProvider != null) { packages = DependencyResolveUtility.FilterPackagesByConstraints(constraintProvider, packages, packageId, allowPrereleaseVersions); } return(packages.FirstOrDefault <IPackage>()); }
/// <summary> /// Finds a package in the wrapped <see cref="IPackageRegistry"/> or <see cref="IPackageLookup"/>. /// As this is used to "fake" the existence of certain packages, the resulting package can be of type <see cref="NullPackage"/>. /// </summary> /// <returns>A valid <see cref="IPackage"/> if found; null, otherwise.</returns> public IPackage FindPackage(string packageId, SemanticVersion version) { var package = _packageRegistry.FindPackage(packageId, version); return(package ?? _packageLookup.FindPackage(packageId, version)); }