Sort packages.lock.json by name to reduce diff churn #14115
Labels
Area:RestoreRepeatableBuild
The lock file features
Functionality:Restore
help wanted
Considered good issues for community contributions.
Priority:3
Issues under consideration. With enough upvotes, will be reconsidered to be added to the backlog.
Type:Feature
NuGet Product(s) Involved
NuGet.exe
The Elevator Pitch
Current packages.lock.json files are generated in a way that makes diffing them non-user-friendly. When moving to central package management (CPM), there is the addition of the


CentralTransitive
type, and these packages are generated at the bottom of the lock file after all theTransitive
packages.For instance, when comparing two lock files; one before adding CPM and one after adding CPM, if I were to try and compare the packages.lock.json files, I would see a diff like this:
Note the change from
Transitive
toCentralTransitive
after the move to CPM.Despite there being no difference in package version here, diffing the two files shows an initially large seeming change, when really the text was just moved to the bottom.
Particularly after enabling transitive pinning, diffing two lock files can be a powerful tool in validating any changes to transitive dependency versions. However, due to the way the files are generated the diff is not as useful as it could be.
The offending source code is here: LockFileFormat.cs where
CentralTransitive
packages are written to the lock file last.TLDR: Is it possible to sort the packages by name when generating the lock file to reduce diff churn?
Thanks for taking the time to hear me out!
Additional Context and Details
Repro steps:
RestorePackagesWithLockFile
MSBuild property to a .csproj or Directory.Build.props to generate the lock file for each project. Save these somewhere outside of the project.dotnet restore
and then diff the new packages.lock.json files with the ones from the previous step (pre-CPM). You should see that some packages are now at the bottom, since they have been given the typeCentralTransitive
.The text was updated successfully, but these errors were encountered: