Repository navigation
Closed
Labels
Area:NuGetAuditBreaking-ChangeLabel for .NET SDK breaking changes.Category:Quality WeekIssues that should be considered for quality weekFunctionality:Whydotnet nuget whyPriority:2Issues for the current backlog.Product:dotnet.exeSeQualityType:DCRDesign Change Request
Milestone
Description
NuGet Product(s) Affected
dotnet.exe
Current Behavior
I just tried to use dotnet nuget why to figure out why a specific package was resolved to a higher version than the one I (the owner of one of the directly referenced packages) expected. However, the version of the package I was looking at was listed as the final resolved version for every leaf.
❯ dotnet nuget why . System.Text.Json
Project 'Microsoft.NET.Sdk' has the following dependency graph(s) for 'System.Text.Json':
[net472]
│
├─ Microsoft.Build (v17.8.3)
│ └─ System.Text.Json (v9.0.0-rc.2.24427.10)
├─ Microsoft.Deployment.DotNet.Releases (v2.0.0-preview.1.24406.1)
│ └─ System.Text.Json (v9.0.0-rc.2.24427.10)
├─ Microsoft.Extensions.DependencyModel (v9.0.0-rc.2.24427.10)
│ └─ System.Text.Json (v9.0.0-rc.2.24427.10)
├─ Microsoft.NET.HostModel (v9.0.0-rc.2.24427.10)
│ └─ System.Text.Json (v9.0.0-rc.2.24427.10)
├─ NuGet.ProjectModel (v6.12.0-preview.1.85)
│ └─ NuGet.DependencyResolver.Core (v6.12.0-preview.1.85)
│ └─ NuGet.Protocol (v6.12.0-preview.1.85)
│ └─ System.Text.Json (v9.0.0-rc.2.24427.10)
└─ System.Text.Json (v9.0.0-rc.2.24427.10)
[net9.0]
│
├─ Microsoft.Deployment.DotNet.Releases (v2.0.0-preview.1.24406.1)
│ └─ System.Text.Json (v9.0.0-rc.2.24427.10)
├─ Microsoft.NET.HostModel (v9.0.0-rc.2.24427.10)
│ └─ System.Text.Json (v9.0.0-rc.2.24427.10)
└─ System.Text.Json (v9.0.0-rc.2.24427.10)Desired Behavior
I expected something like this (reconstructed from project.assets.json info):
❯ dotnet nuget why . System.Text.Json
Project 'Microsoft.NET.Sdk' has the following dependency graph(s) for 'System.Text.Json':
[net472]
│
├─ Microsoft.Build (v17.8.3)
│ └─ System.Text.Json (v7.0.3)
├─ Microsoft.Deployment.DotNet.Releases (v2.0.0-preview.1.24406.1)
│ └─ System.Text.Json (v8.0.3)
├─ Microsoft.Extensions.DependencyModel (v9.0.0-rc.2.24427.10)
│ └─ System.Text.Json (v9.0.0-rc.2.24427.10)
├─ Microsoft.NET.HostModel (v9.0.0-rc.2.24427.10)
│ └─ System.Text.Json (v8.0.0)
├─ NuGet.ProjectModel (v6.12.0-preview.1.85)
│ └─ NuGet.DependencyResolver.Core (v6.12.0-preview.1.85)
│ └─ NuGet.Protocol (v6.12.0-preview.1.85)
│ └─ System.Text.Json (v8.0.4)
└─ System.Text.Json (v9.0.0-rc.2.24427.10)
[net9.0]
│
├─ Microsoft.Deployment.DotNet.Releases (v2.0.0-preview.1.24406.1)
│ └─ System.Text.Json (v8.0.3)
├─ Microsoft.NET.HostModel (v9.0.0-rc.2.24427.10)
│ └─ System.Text.Json (v8.0.0)
└─ System.Text.Json (v9.0.0-rc.2.24427.10)Additional Context
I think this'd help answer the question "why is this package referenced at this version"--currently dotnet nuget why helps figure out where it came from transitively but not the versioning.
Reacted by Brandon, sostrich, Frulfump, cremor and Seiji Suenaga
Metadata
Metadata
Assignees
Labels
Area:NuGetAuditBreaking-ChangeLabel for .NET SDK breaking changes.Category:Quality WeekIssues that should be considered for quality weekFunctionality:Whydotnet nuget whyPriority:2Issues for the current backlog.Product:dotnet.exeSeQualityType:DCRDesign Change Request
Activity
zivkan commentedon May 7, 2025
I've been thinking about how to implement this, and there's one complication.
If I have a csproj with
<PackgeReference Include="Newtonsoft.Json" Version="9.0.0" />, NuGet will report a NU1603 warning that 9.0.0 doesn't exist and will restore 9.0.1 instead. It will later output a NU1903 warning saying that 9.0.1 has a known vulnerability. But imagine there's lots of restore output, so the NU1603 and NU1903 warnings are not adjacent. I think it's very feasible that your only see the vulnerable package warning, and not the NU1603 warning, and therefore be unaware that NuGet was asked to download a version that doesn't exist.I don't like the idea of reporting two versions for every package, like
dotnet list packagedoes.But if
dotnet nuget whyonly reports referenced versions, then the package tree won't show 9.0.1 anywhere, and it could be confusing why restore said that version is vulnerable.What do other people think?
One option is to have a note in
dotnet nuget why's usage help message, saying that the reported versions may be different to the resolved version and to usedotnet list packageto check.zivkan commentedon May 8, 2025
Another idea is to mark the highest version of each package (technically, the range with the highest min version) with something like a
*. It's not guaranteed to be the resolved (selected) version, but it's hopefully good enough.Frulfump commentedon Jun 26, 2025
I would like to see both requested and resolved version as it would help me figure out what's happening with one tool call.
Currently I need to switch between looking at the csproj, and checking nuget.org for the different packages dependencies that I'm interested in to figure out why I get
A lock file helps a bit over using the
project.assets.jsonbut is still manual work.I don't see an issue with reporting two versions for every package.
Yeah I think that could be a bit confusing and non-obvious to figure out why as you've listed in your example.
Using .NET 10.0.100-preview.5.25277.114
dotnet list packageonly lists top-level packages with requested and resolved version butdotnet list package --include-transitiveonly lists resolved versions so it doesn't help answer the question why a version is being pulled in (resolved) for a transitive dependency.Maybe I misunderstood how
dotnet list packagecould be used here?I didn't fully understand this one could you provide an example?
zivkan commentedon Jul 1, 2025
How should it be shown? Let's start with a simple example:
Which is the requested version, and which is the resolved version? Normally we'd guess that the higher version is the resolved version, but if I'm using the direct-dependency-wins rule to intentionally downgrade a transitive dependency, then the order would be
We can add labels:
But this makes the line considerably longer. 39 characters vs 18 with no labels, or just 8/9 when only showing one version.
When I open Windows Terminal on Windows, or KDE's terminal in Linux, it defaults to 80 characters wide. So, the longer the version string per line, the more likely the lines are going to wrap and make it harder to read. I expect most people immediately maximise their terminal, so use considerably more than 80 characters, so I'm not sure what width to optimise the output for, but I think 80 being the default is a good starting point.
Direct packages/projects start of at 6 columns indentation, and each level of nesting adds another 3. Doing
dotnet nuget why Microsoft.Data.SqlClientin the OrchardCore repo, I see a bunch of instances nested around 40 characters deep. If the two version strings with labels uses about 40 characters, and the tree indentation is also around 40, then the line's going to wrap on the 80 character wide terminal.There are a bunch of packages on nuget.org that have a package id length of 100, but they all look like spam/malware. But there are a bunch of valid looking packages whose ID is over 80, and even more over 70 characters long. Average is 25 characters long
I've been accused of overthinking things before, and I'm sure I will be again in the future. This might be one of those times. But when thinking about user experience, this is one of the things I consider. Especially since I've personally experienced times where some command with long output does line wrapping, making things harder to read.
What I meant was use
dotnet nuget whyto see the requested versions, and then usedotnet package listto see the resolved version. It goes against your first sentence saying you'd like to see it by running one tool command.Knowing exactly how people are going to use
whywould be helpful. If I have a restore warning saying that Contoso.Utils 3.2.1 has a known vulnerability, then I know this is the resolved version. Runningdotnet nuget why Contoso.Utilsand having the resolved version making lines wrap, and therefore even harder to read, doesn't help. I know what the resolved version is.On the other hand, if I'm trying to learn about any of the other packages in the graph, then having requested and resolved will avoid me needing to run multiple commands, and trying to consolidate information from the two commands.
But this doesn't solve the problem when requesting version 13.0.0 of Newtonsoft.Json, and it reolsves 13.0.1 instead.
zivkan commentedon Jul 1, 2025
Writing the above made me think of another complication, although it's related to the fundamental issue of the original request.
A package's dependencies change based on the package version. This is probably painfully obvious, but the current implementation of
dotnet nuget whyshows only the resolved versions, which means that every time PackageX is displayed, it has the same dependencies.For example, say Contoso.Utils version 1.0.0 has a dependency on System.Memory, but version 2.0.0 removes that dependency.
The graph could now be misleading to some people, because System.Memory was culled from the graph, the project is not using that package, because Contoso.API's dependency of Contoso.Utils was upgraded elsewhere in the graph.
If we remove System.Memory from the graph, then it's also misleading because Contoso.Utils v1.0.0 really does have a dependency on System.Memory. Is that useful for the person who ran
whyto know? Depends on the context, maybe or maybe not.I think this complication makes it more important to add resolved versions to the why output, because it's hopefully more clear that a package without a resolved version is a package that was remvoed from the graph, and not used by the project.
Originally I was thinking to implement this request as "why always does this". Now I'm thinking maybe adding a
--show-requestedoption.8 remaining items
aortiz-msft commentedon Feb 14, 2026
@Frulfump
Yes, no worries. We will take care of it!
zivkan commentedon Mar 13, 2026
Unfortunately we need to provide an opt-out to maintain the same text output as before the change, which I don't have the time for right now, so the change was reverted for now.
Frulfump commentedon Mar 13, 2026
Of course lol 😅. Back-compat for everything!!!
Hope you get some time to soon 😃
Frulfump commentedon May 9, 2026
Thanks for getting this over the finishing line (again), will be great to use it irrespective of the version of the .NET SDK it ends up in!