Repository navigation
Upgrade literal GlobalPackageReference versions without dotnet add - #851
Merged
Merged
Conversation
`dotnet add package` can't update a GlobalPackageReference: it adds a
PackageReference to the project, which central package management
rejects ("PackageVersion ... defined in incorrect location"). Since
#697 a GlobalPackageReference with a literal version went through it
unless --no-restore was set, so `--upgrade` failed (#681).
The version locator now asks the evaluator whether a package's version
comes from a GlobalPackageReference and in which file, and the upgrade
writes that file directly and restores the project once (shared with
the variable path's restore-once logic). This also handles a
GlobalPackageReference declared outside Directory.Packages.props.
Fixes #681
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #681.
Problem
dotnet outdated --upgradefails for aGlobalPackageReferencewith a literal version:Since #697 these upgrades went through
dotnet add package(unless--no-restorewas set). That command can't update aGlobalPackageReference: it adds aPackageReferenceto the project, which central package management rejects. AGlobalPackageReferencewhose version came from an MSBuild property was already written directly, so only the literal case was broken.Fix
IProjectEvaluator.GetGlobalPackageReferenceFilereports which file'sGlobalPackageReferencesets a package's version.MSBuildEvaluatoralready tracked these items. As inGetVersionVariables, aPackageReferenceversion takes precedence.VersionLocatorreturns a newGlobalPackageReferenceVersionlocation for this case.DotNetPackageServicewrites the version in that file (formatting and encoding unchanged) and then restores.RestoreOncehelper. A multi-targeted project, or several projects sharing the reference, restores once per project rather than once per target framework.GlobalPackageReferenceinDirectory.Build.propsis upgraded too. Before, onlyDirectory.Packages.propswas searched, even with--no-restore.Tests
--no-restore(attribute layouts, child elements, conditionalItemGroup), restoring once across target frameworks, and aGlobalPackageReferenceinDirectory.Build.propswith and without--no-restore. All 6 fail without the fix.GlobalPackageReferencecase fromCpmProjectWithRestore_PreservesPackageAttributeFormatting. It mockeddotnet add packagesuccessfully updating aGlobalPackageReference, which realdotnetdoesn't do, and is how this bug got past the tests.StyleCop.Analyzers 1.2.0-beta.556failed on master. With this branch it upgrades to1.3.180, and a second run reports no outdated dependencies.🤖 Generated with Claude Code