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

Ensure the dependencies' versions match the registry #283

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions src/UnityNuGet/RegistryCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -379,18 +379,35 @@ private async Task BuildInternal()

PackageDependency? packageDependency = null;

foreach (var dependencyPackageMeta in dependencyPackageMetas)
{
var dependencyResolvedDependencyGroups = NuGetHelper.GetCompatiblePackageDependencyGroups(dependencyPackageMeta.DependencySets, _targetFrameworks, includeAny: false);
// Get the registry entry for the dependency
_registry.TryGetValue(deps.Id, out var registryEntry);
var registryMinimumVersion = registryEntry?.Version?.MinVersion!;

if (dependencyResolvedDependencyGroups.Any())
// Try to find a match
if (registryEntry != null)
{
foreach (var dependencyPackageMeta in dependencyPackageMetas)
{
_registry.TryGetValue(dependencyPackageMeta.Identity.Id, out var registryEntry);

var registryMinimumVersion = registryEntry?.Version?.MinVersion!;

NuGetVersion newVersion = registryMinimumVersion > dependencyPackageMeta.Identity.Version ? registryMinimumVersion : dependencyPackageMeta.Identity.Version;

var dependencyResolvedDependencyGroups = NuGetHelper.GetCompatiblePackageDependencyGroups(dependencyPackageMeta.DependencySets, _targetFrameworks, includeAny: false);
if (!dependencyResolvedDependencyGroups.Any())
{
continue;
}

var v = dependencyPackageMeta.Identity.Version;
if (registryEntry.Version != null)
{
// If the registry specifies a version range, ensure the dependency falls within that range
var packageVersionRange = new VersionRange(v, includeMinVersion: true, v, includeMaxVersion: true);
var commonVersionRange = VersionRange.CommonSubSet(new[] { packageVersionRange, registryEntry.Version });

if (commonVersionRange == VersionRange.None)
{
continue;
}
}

NuGetVersion newVersion = registryMinimumVersion > v ? registryMinimumVersion : v;
packageDependency = new PackageDependency(dependencyPackageMeta.Identity.Id, new VersionRange(newVersion));

break;
Expand Down