cake-build / cake-build/cake

Get best match when using VersionRange

Open
#2,566 1 comment 0 reactions 0 assignees View on GitHub
Improvement
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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.