private PackageSearchResponse MergeResults(IEnumerable <SimpleSearchMetadata>[] results, IEnumerable <SourceRepository> repos) { var comparer = new PackageIdentityComparer(); return(new PackageSearchResponse() { Packages = results .SelectMany(metadata => metadata) .GroupBy(metadata => metadata.Identity.Id) .Select(metadataGroup => metadataGroup.OrderByDescending(metadata => metadata.Identity, comparer).First()) .OrderBy(metadata => metadata.Identity.Id) .Select(metadata => new PackageSearchItem() { Id = metadata.Identity.Id, Version = metadata.Identity.Version.ToNormalizedString(), HasVersion = metadata.Identity.HasVersion, Description = metadata.Description }) }); }
public ResolverComparer(DependencyBehavior dependencyBehavior, HashSet <PackageIdentity> preferredVersions, HashSet <string> targetIds) { _dependencyBehavior = dependencyBehavior; _preferredVersions = preferredVersions; _targetIds = targetIds; _versionComparer = VersionComparer.Default; _identityComparer = PackageIdentity.Comparer; _installedVersions = new Dictionary <string, NuGetVersion>(); if (_installedVersions != null) { foreach (var package in _preferredVersions) { if (package.Version != null) { _installedVersions.Add(package.Id, package.Version); } } } }