Respect package update version ranges#7323
Conversation
Preserve PackageReference and central PackageVersion upper bounds during update selection so tooling avoids out-of-range package versions and keeps constraints on write.
Only enforce authored update ranges for floating or upper-bounded constraints so fixed PackageReference versions do not block explicit downgrade actions.
|
Does it allow upgrading with the version out of the range but with the saved intent? For example: |
Cover the range-vs-range out-of-bound scenarios and positive guardrails across the dotnet package update XPlat path, the PM UI / PMC path, and the PackageUpdateIO latest-version filter.
|
@voroninp: No |
|
. |
|
@Saibamen Thanks for creating this PR, this is a good change for the Package Manager UI and solves some of the pains listed in the original issue. But I don't think this PR fixes it completely so we will need to create a new issue, so we don't close the original. Also, this is a change in design, so we need to have a design spec for this and have a review with the team. I assigned this to myself and will work on a spec next week so we can all review it. |
|
This PR has been automatically marked as stale because it has no activity for 7 days. It will be closed if no further activity occurs within another 30 days of this comment. If it is closed, you may reopen it anytime when you're ready again, as long as you don't delete the branch. |
Summary
Fixes the version-range update behavior tracked in NuGet/Home#6566. When package update tooling evaluates an installed
PackageReferenceor centralPackageVersionwith an authored version range, NuGet now respects that range while selecting update candidates and preserves the authored constraint when writing the update back.Previously, update flows could select versions outside an existing upper bound, or replace a bounded range such as
[1.0.0, 2.0.0)with a fixed version after a successful in-range update. This made update behavior inconsistent across PM UI, Package Manager Console, anddotnet package update, and could silently discard constraints that users intentionally authored.Fixes: NuGet/Home#6566
Behavior
Updates now preserve version-range intent when all are true:
PackageReferenceor centralPackageVersionvalue.For upper-bounded ranges, NuGet updates the lower bound to the selected package version while keeping the original upper bound. Floating ranges are preserved as authored. Explicit update requests outside an authored floating or upper-bounded range are rejected or skipped instead of producing an out-of-range install action. Fixed PackageReference versions are treated as normal installed versions, not authored update constraints, so explicit downgrade operations continue to work.
Implementation
The change carries the installed
VersionRangethrough package update action creation inNuGetPackageManagerso PM UI and Package Manager Console flows can reject out-of-range explicit updates and preserve allowed ranges for in-range updates.For
dotnet package update, latest-version resolution now accepts an optional allowed range and filters package source results before selecting the highest candidate. The command runner also reads central package version ranges when Central Package Management is enabled, so CPM updates follow the same range-preserving behavior as project-localPackageReferenceupdates.Test plan
dotnet test test\NuGet.Core.Tests\NuGet.CommandLine.Xplat.Tests\NuGet.CommandLine.Xplat.Tests.csproj --filter FullyQualifiedName~GetPackageToUpdateTests --no-restoredotnet test test\NuGet.Core.Tests\NuGet.PackageManagement.Test\NuGet.PackageManagement.Test.csproj --filter FullyQualifiedName~BuildIntegratedTests --no-restoredotnet test test\NuGet.Core.FuncTests\NuGet.XPlat.FuncTest\NuGet.XPlat.FuncTest.csproj --filter FullyQualifiedName~GetLatestVersionAsyncTests --no-builddotnet format whitespace --verify-no-changes NuGet.slnNotes / follow-ups