Repository navigation
Preserve MSBuild variable references when upgrading packages - #714
Merged
slang25 merged 9 commits intoFeb 22, 2026
Merged
Conversation
Implements variable tracking and preservation for both CPVM and direct PackageReference scenarios. When packages use MSBuild properties like Version="$(PropertyName)", the tool now: - Discovers and tracks variable references before upgrading packages - Updates the property value instead of replacing with literal versions - Preserves the variable reference syntax in package declarations - Handles shared properties used by multiple packages - Includes caching to optimize performance when processing multiple packages Changes: - Add VariableTrackingService to discover and track property-based versions - Update CentralPackageVersionManagementService to preserve CPVM variable references - Update DotNetPackageService to restore variable references after dotnet add package - Register VariableTrackingService in DI container - Add integration tests for both CPVM and direct reference scenarios - Add test projects demonstrating variable usage patterns All 155 tests passing.
- Move RestoreVariableReference method from DotNetPackageService to VariableTrackingService - Rename to UpdatePackageVariable for better clarity - Simplify method signature to use PackageVariableInfo directly instead of redundant parameters - Add cache invalidation after file updates to ensure data consistency - Remove unused System.Xml.Linq and System.Linq imports from DotNetPackageService - Encapsulate all variable management logic in a single service
Minor cleanup, removal of unused things
- Create test-projects/cpvm-variables with Directory.Packages.props - Add test case Can_Upgrade_CPVM_With_Variables_Preserves_Variable_References - Verify that variable references like $(NewtonsoftJsonVersion) are preserved in Directory.Packages.props - Test confirms that VariableTrackingService works correctly with Central Package Management
- Add PackageReferenceFilePath to track where package reference is used separately from where property is defined - Refactor DiscoverPackageVariables to collect all property definitions first, then match with package references - Update UpdatePackageVariable to update both property file and package reference file - Add test for variables defined in Directory.Build.props and used in project file - Fixes scenario where variable is defined in one file but used in another
hwoodiwiss
force-pushed
the
support-version-variables
branch
from
February 18, 2026 07:54
4d90f36 to
3f8906f
Compare
hwoodiwiss
commented
Feb 18, 2026
Contributor
Author
There was a problem hiding this comment.
Based on the .gittattributes, LF seems to be correct, but the repo currently has CRLF. Is it okay to review this with &w=1? If not I can update the gitattributes to follow what's currently in the repo.
Member
There was a problem hiding this comment.
Yeah, I'll fix up the line endings after
…ilure - Add VariableTrackingServiceTests covering Discover and Update paths, including caching, cross-file, CPVM, and GlobalPackageReference scenarios - Add optional Action<string> onWarning callback to VariableTrackingService so failures in UpdatePackageVariable are reported rather than silently dropped - Wire the callback to IReporter.Warn in Program.cs DI registration - Fix class comment style (remove malformed // <summary> XML tags) Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
slang25
approved these changes
Feb 22, 2026
github-actions Bot
pushed a commit
to EelcoLos/nx-tinkering
that referenced
this pull request
Mar 2, 2026
Updated [dotnet-outdated-tool](https://github.com/dotnet-outdated/dotnet-outdated) from 4.7.0 to 4.7.1. <details> <summary>Release notes</summary> _Sourced from [dotnet-outdated-tool's releases](https://github.com/dotnet-outdated/dotnet-outdated/releases)._ ## 4.7.1 ## What's Changed * Fix --no-restore corrupting .csproj in CPM projects by @slang25 in dotnet-outdated/dotnet-outdated#713 * Add Claude Code GitHub Workflow by @slang25 in dotnet-outdated/dotnet-outdated#716 * Preserve MSBuild variable references when upgrading packages by @hwoodiwiss in dotnet-outdated/dotnet-outdated#714 ## New Contributors * @hwoodiwiss made their first contribution in dotnet-outdated/dotnet-outdated#714 **Full Changelog**: dotnet-outdated/dotnet-outdated@v4.7.0...v4.7.1 Commits viewable in [compare view](dotnet-outdated/dotnet-outdated@v4.7.0...v4.7.1). </details> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This was referenced Mar 3, 2026
github-actions Bot
pushed a commit
to ptr727/LanguageTags
that referenced
this pull request
Mar 3, 2026
Updated [dotnet-outdated-tool](https://github.com/dotnet-outdated/dotnet-outdated) from 4.7.0 to 4.7.1. <details> <summary>Release notes</summary> _Sourced from [dotnet-outdated-tool's releases](https://github.com/dotnet-outdated/dotnet-outdated/releases)._ ## 4.7.1 ## What's Changed * Fix --no-restore corrupting .csproj in CPM projects by @slang25 in dotnet-outdated/dotnet-outdated#713 * Add Claude Code GitHub Workflow by @slang25 in dotnet-outdated/dotnet-outdated#716 * Preserve MSBuild variable references when upgrading packages by @hwoodiwiss in dotnet-outdated/dotnet-outdated#714 ## New Contributors * @hwoodiwiss made their first contribution in dotnet-outdated/dotnet-outdated#714 **Full Changelog**: dotnet-outdated/dotnet-outdated@v4.7.0...v4.7.1 Commits viewable in [compare view](dotnet-outdated/dotnet-outdated@v4.7.0...v4.7.1). </details> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore <dependency name> major version` will close this group update PR and stop Dependabot creating any more for the specific dependency's major version (unless you unignore this specific dependency's major version or upgrade to it yourself) - `@dependabot ignore <dependency name> minor version` will close this group update PR and stop Dependabot creating any more for the specific dependency's minor version (unless you unignore this specific dependency's minor version or upgrade to it yourself) - `@dependabot ignore <dependency name>` will close this group update PR and stop Dependabot creating any more for the specific dependency (unless you unignore this specific dependency or upgrade to it yourself) - `@dependabot unignore <dependency name>` will remove all of the ignore conditions of the specified dependency - `@dependabot unignore <dependency name> <ignore condition>` will remove the ignore condition of the specified dependency and ignore conditions </details> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This was referenced Mar 3, 2026
This was referenced Apr 12, 2026
This was referenced Apr 19, 2026
This was referenced Apr 26, 2026
This was referenced May 6, 2026
This was referenced May 17, 2026
This was referenced May 24, 2026
This was referenced Jun 7, 2026
This was referenced Jun 14, 2026
slang25
added a commit
to GREsau/dotnet-outdated
that referenced
this pull request
Nov 8, 2026
Resolves conflicts with variable tracking (dotnet-outdated#714), the CPM --no-restore direct write (dotnet-outdated#713), file-based apps (dotnet-outdated#752/dotnet-outdated#755) and short TFM names (dotnet-outdated#750). AddPackage now takes the VersionRange through all of master's new paths; single-version paths use the range's lower bound for now (refined in follow-up commits). Restores the System.Text.Json using needed by master's tests and adapts DotNetPackageServiceTests to the new signature. 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.
AI Usage
This PR was mostly created using AI, specifically Claude Sonnet 4.5/4.6, using OpenCode. The design was my idea, the implementation came from the friendly robot.
Problem
When a project uses MSBuild properties to manage package versions (e.g.
Version="$(NewtonsoftJsonVersion)"), runningdotnet outdated --upgradewould overwrite the variable reference with a literal version string. This broke the project's version management strategy and required manual cleanup after every upgrade.Solution
Introduces
VariableTrackingService, a new Core service that detects MSBuild variable references in package versions before an upgrade and restores them afterwards. The service performs a two-step operation around thedotnet add packagecall:.propsfiles in the directory hierarchy to build a map of which packages use variable references and where those variables are defined.dotnet add packageoverwrites the version with a literal string, updates the property definition to the new version value and restores the$(VariableName)reference in thePackageReference(orPackageVersion) element.Supported scenarios
All three common variable reference patterns are supported:
.csprojPackageVersionelements with variable references inDirectory.Packages.propsDirectory.Build.props(or any.propsfile in a parent directory), used in a.csprojNot supported
<FooVersion>$(GroupVersion)</FooVersion>), the service will not trace through the chain. The upgrade will proceed but the variable reference will be replaced with a literal version string.Condition="..."attributes on<PropertyGroup>or individual property elements are ignored. The first unconditional definition of a property wins.$(MajorVersion).$(MinorVersion).0) are not recognised as version values and will not be tracked..propsfiles — only.propsfiles found by walking up the directory tree from the project are scanned. Properties imported from SDK targets, NuGet packages, or other non-standard locations are not resolved.In all unsupported cases the upgrade proceeds normally — the package version is updated successfully, but the variable reference is not preserved.
Changes
DotNetOutdated.Core/Services/VariableTrackingService.csPackageVariableInfodata classDotNetOutdated.Core/Services/DotNetPackageService.csIVariableTrackingService; call discover/update arounddotnet add packageDotNetOutdated/Program.csVariableTrackingServicein the DI containertest-projects/direct-reference-variables/test-projects/cpvm-variables/test-projects/cross-file-variables/test/DotNetOutdated.Tests/EndToEndTests.csNotes
IFileSystemabstraction is respected throughout, keeping the service fully unit-testable.