Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get best match when using VersionRange #2566

Open
glennawatson opened this issue Jun 14, 2019 · 1 comment
Open

Get best match when using VersionRange #2566

glennawatson opened this issue Jun 14, 2019 · 1 comment

Comments

@glennawatson
Copy link

glennawatson commented Jun 14, 2019

Hey there,

On ReactiveUI.Pharamacist we use the same version matching as the NuGet team use.

So they have a built in method called "GetBestMatch" and they grab the version information from the NuGet server.

https://github.com/reactiveui/Pharmacist/blob/master/src/Pharmacist.Core/NuGet/NuGetPackageHelper.cs

IReadOnlyCollection<LibraryRange> LibraryIdentities;

// Use the provided nuget package source, or use nuget.org
var sourceRepository = new SourceRepository(nugetSource ?? new PackageSource(DefaultNuGetSource), Providers);

var packages = await Task.WhenAll(LibraryIdentities.Select(x => GetBestMatch(x, sourceRepository, token))).ConfigureAwait(false);

/// <summary>
/// Gets the best matching PackageIdentity for the specified LibraryRange.
/// </summary>
/// <param name="identity">The library range to find the best patch for.</param>
/// <param name="sourceRepository">The source repository where to match.</param>
/// <param name="token">A optional cancellation token.</param>
/// <returns>The best matching PackageIdentity to the specified version range.</returns>
public static async Task<PackageIdentity> GetBestMatch(LibraryRange identity, SourceRepository sourceRepository, CancellationToken token)
{
    var findPackageResource = await sourceRepository.GetResourceAsync<FindPackageByIdResource>(token).ConfigureAwait(false);

    var versions = await findPackageResource.GetAllVersionsAsync(identity.Name, _sourceCacheContext, _logger, token).ConfigureAwait(false);

    var bestPackageVersion = versions?.FindBestMatch(identity.VersionRange, version => version);

    return new PackageIdentity(identity.Name, bestPackageVersion);
}

At the moment you are just using the "Min Version" which is not always correct.

@glennawatson glennawatson changed the title Add support for NuGet LibraryRange Add support for NuGet LibraryRange or VersionRange Jun 14, 2019
@glennawatson glennawatson changed the title Add support for NuGet LibraryRange or VersionRange Get best match when using VersionRange Jun 14, 2019
@glennawatson glennawatson reopened this Jun 14, 2019
@glennawatson
Copy link
Author

Changed to mention that it should be using best version matching. At the moment the min is not a great match.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants