Skip to content

dotnet nuget why reports requested as well as resolved versions#7017

Merged
zivkan merged 10 commits intodevfrom
dev-zivkan-why-requested-version
Jan 29, 2026
Merged

dotnet nuget why reports requested as well as resolved versions#7017
zivkan merged 10 commits intodevfrom
dev-zivkan-why-requested-version

Conversation

@zivkan
Copy link
Copy Markdown
Member

@zivkan zivkan commented Dec 23, 2025

Bug

Fixes: NuGet/Home#13752
FIxes: NuGet/Home#14695

Description

Shows the requested and resolved versions for each package. Removes the version for project references, making it more obvious that the graph node is indeed a project.

The above feature modified the same lines needed to fix running why on a legacy csproj, so both are being fixed in the same pull request, rather than two PRs that would need to be opened sequentially.

I used copilot to implement showing the requested version, but when reviewing its changes to DependencyGraphFinder.cs, I found the file's algorithm confusing. So, I commit copilot's changes unreviewed, then rewrote the class from scratch, with a few small changes in other files. Overall, it reduces product code by about 100 lines. If my rewrite isn't liked, we can revert the refactor commit from the branch, but then if someone has questions about the changes to DependencyGraphFinder, I may not be able to answer it.

The algorithm of the new class is, for each target in the assets file, create an in-memory LockFileTargetLibrary with the project's direct package and project references as dependencies, then recursively convert a LockFileTargetLibrary into a DependencyNode. It does this with no intermediate state, other than the "fake" LockFileTargetLibrary for the project's root. The tree is filtered for the package requested on the dotnet package why command line, but the way it's written, it will be trivial (change one if statement) to either show the complete unfiltered tree, or filter on multiple packages, or a partial package id match.

The implementation has a performance optimization, so it doesn't create the tree/graph and then filter as a second step. Instead, it returns nulls when the package is filtered out and there are no children. Dependencies that return null are removed, so when no dependency has the package, the node looks like it has no dependencies and so also gets removed if the package name also doesn't match. So, entire subtrees that don't contain the searched requested package avoid being created, with minimal (hopefully zero) memory allocations.

In order to have stronger guarantees on nullability, I modified DependencyNode to be an abstract class so PackageNodes must have both a requested version and resolved version.

The refactor found some tests that use an invalid assets file. I deleted these tests as the multi-rid nature of the tests are very difficult to replicate, but mostly test scenarios that theoretically possible, but not really practical. I'll comment on the two assets files explaining which each is infeasible, as justification why to delete the test rather than spending a lot of effort to fix it.

PR Checklist

@zivkan zivkan requested a review from a team as a code owner December 23, 2025 04:51
@zivkan zivkan marked this pull request as draft December 23, 2025 05:02
@zivkan zivkan marked this pull request as ready for review December 24, 2025 01:00
@zivkan
Copy link
Copy Markdown
Member Author

zivkan commented Dec 24, 2025

Using the same example that @rainersigwald used in the original feature request, it looks like this now:

image

Big thanks to @Frulfump for the formatting idea that I really like and implemented.

@dotnet-policy-service dotnet-policy-service bot added the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Dec 31, 2025
@zivkan zivkan removed the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Jan 1, 2026
Copy link
Copy Markdown

@Frulfump Frulfump left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to see this being implemented, can't wait to use it!

Comment thread src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Why/DependencyGraphFinder.cs Outdated
@jeffkl jeffkl self-requested a review January 6, 2026 23:19
donnie-msft
donnie-msft previously approved these changes Jan 8, 2026
Comment thread src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Why/DependencyGraphFinder.cs Outdated
martinrrm
martinrrm previously approved these changes Jan 9, 2026
Copy link
Copy Markdown
Contributor

@martinrrm martinrrm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments not blocking this PR. Great refactor!

Comment thread src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Why/DependencyNode.cs Outdated
@zivkan zivkan dismissed stale reviews from martinrrm and donnie-msft via a699f68 January 11, 2026 21:20
martinrrm
martinrrm previously approved these changes Jan 12, 2026
donnie-msft
donnie-msft previously approved these changes Jan 12, 2026
jeffkl
jeffkl previously approved these changes Jan 12, 2026
@zivkan zivkan marked this pull request as draft January 14, 2026 23:08
@dotnet-policy-service dotnet-policy-service bot added the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Jan 22, 2026
@Frulfump
Copy link
Copy Markdown

Oh this was set to draft which was done due to the one failing check I presume?

@dotnet-policy-service dotnet-policy-service bot removed the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Jan 22, 2026
@zivkan
Copy link
Copy Markdown
Member Author

zivkan commented Jan 25, 2026

I think the floating version display is unacceptable, so I want to fix that. I just haven't had time yet.

@zivkan zivkan dismissed stale reviews from donnie-msft and martinrrm via 186b839 January 27, 2026 05:59
@zivkan zivkan force-pushed the dev-zivkan-why-requested-version branch from a699f68 to 186b839 Compare January 27, 2026 05:59
@zivkan zivkan marked this pull request as ready for review January 27, 2026 06:03
jeffkl
jeffkl previously approved these changes Jan 27, 2026
Copy link
Copy Markdown
Member

@nkolev92 nkolev92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do like the new version of the algorithm.

I did have to review it completely separately from the old one though, so that wasn't fun :D

Mostly slow comments, that probably wouldn't have caught if this wasn't a full rewrite. I figured if we're rewriting it all, it's a good opportunity for more improvements.

Comment thread src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Why/DependencyGraphFinder.cs Outdated
Comment thread src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Why/DependencyGraphFinder.cs Outdated
Comment thread src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Why/DependencyGraphFinder.cs Outdated
Comment thread src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Why/DependencyGraphFinder.cs Outdated
Comment thread src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Why/DependencyGraphFinder.cs Outdated
@zivkan zivkan merged commit 1a85f19 into dev Jan 29, 2026
17 of 18 checks passed
@zivkan zivkan deleted the dev-zivkan-why-requested-version branch January 29, 2026 20:26
@aortiz-msft aortiz-msft added the Breaking-change Label for .NET SDK breaking changes. label Feb 6, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Added needs-breaking-change-doc-created label because this PR has the breaking-change label.

When you commit this breaking change:

  1. Create and link to this issue a matching issue in the dotnet/docs repo using the breaking change documentation template, then remove this needs-breaking-change-doc-created label.
  2. Ask a committer to mail the .NET SDK Breaking Change Notification email list.

You can refer to the .NET SDK breaking change guidelines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Breaking-change Label for .NET SDK breaking changes. needs-breaking-change-doc-created

Projects

None yet

8 participants