Get best match when using VersionRange
- Dominant language
- C#
- Stars
- 4.2k
- Forks
- 778
- Avg merge
- 3h 37m
- Merged PRs (30d)
- 21
Description
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
```cs
IReadOnlyCollection 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);
///
/// Gets the best matching PackageIdentity for the specified LibraryRange.
///
/// The library range to find the best patch for.
/// The source repository where to match.
/// A optional cancellation token.
/// The best matching PackageIdentity to the specified version range.
public static async Task GetBestMatch(LibraryRange identity, SourceRepository sourceRepository, CancellationToken token)
{
var findPackageResource = await sourceRepository.GetResourceAsync(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.
Contributor guide
Research direction
Start by reviewing the referenced Pharmacist.Core/NuGet/NuGetPackageHelper.cs and its GetBestMatch implementation, then trace Cake’s VersionRange handling where only the minimum version is selected. Confirm the expected behavior for available versions and version ranges, and verify that the selected result is the best matching version rather than merely the minimum.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100