Skip to content

Report real transitive reference versions in dotnet nuget why, not final resolved versions #13752

Closed

Description

@rainersigwald

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.

Activity

  1. added
    Priority:2
    on Sep 23, 2024
  2. self-assigned this
    on Feb 18, 2025
  3. added
    Category:Quality Week
    on Mar 3, 2025
  4. zivkan commented on May 7, 2025

    @zivkan
    Member

    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 package does.

    But if dotnet nuget why only 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 use dotnet list package to check.

  5. zivkan commented on May 8, 2025

    @zivkan
    Member

    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.

  6. Frulfump commented on Jun 26, 2025

    @Frulfump

    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

    NU1608 Detected package version outside of dependency constraint: Microsoft.CodeAnalysis.Workspaces.Common 3.3.1 requires Microsoft.CodeAnalysis.Common (= 3.3.1) but version Microsoft.CodeAnalysis.Common 4.13.0 was resolved.

    A lock file helps a bit over using the project.assets.json but is still manual work.

    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 package does.

    I don't see an issue with reporting two versions for every package.

    But if dotnet nuget why only 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?

    Yeah I think that could be a bit confusing and non-obvious to figure out why as you've listed in your example.

    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 use dotnet list package to check.

    Using .NET 10.0.100-preview.5.25277.114 dotnet list package only lists top-level packages with requested and resolved version but dotnet list package --include-transitive only 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 package could be used here?

    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.

    I didn't fully understand this one could you provide an example?

  7. zivkan commented on Jul 1, 2025

    @zivkan
    Member

    I don't see an issue with reporting two versions for every package.

    How should it be shown? Let's start with a simple example:

       └─ Newtonsoft.Json (v13.0.1) (v9.0.1)
    

    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:

       └─ Newtonsoft.Json (resolved: v13.0.1) (requested: v9.0.1)
    

    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.SqlClient in 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.

    Maybe I misunderstood how dotnet list package could be used here?

    What I meant was use dotnet nuget why to see the requested versions, and then use dotnet package list to 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 why would 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. Running dotnet nuget why Contoso.Utils and 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.

    I didn't fully understand this one could you provide an example?

    Project 'Fabrikam.Backend' has the following dependency graph(s) for 'Contoso.Utils':
    
      [net472]
       │  
       ├─ Contoso.Apis (v1.2.3*)
       │  └─ Contoso.Utils (v1.2.3)
       └─ Fabrikam.Utils (v1.0.0*)
          └─ Contoso.Utils (v2.0.0*)
    
    (*) Highest version for the package in the graph
    

    But this doesn't solve the problem when requesting version 13.0.0 of Newtonsoft.Json, and it reolsves 13.0.1 instead.

  8. zivkan commented on Jul 1, 2025

    @zivkan
    Member

    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 why shows 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.

       ├─ Contoso.Apis (v1.0.0)
       │  └─ Contoso.Utils (v1.0.0)
       │     └─ System.Memory (v1.0.0)
       └─ Fabrikam.Utils (v1.0.0)
          └─ Contoso.Utils (v2.0.0)
    

    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 why to 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-requested option.

  9. 8 remaining items

  10. aortiz-msft commented on Feb 14, 2026

    @aortiz-msft
    Contributor

    For changes in NuGet functionality (such as NuGet Restore changes), refer to the .NET SDK breaking change guidelines

    What should I do with this information?! The message should be updated so it's clearly geared towards Microsoft personel.

    cc @aortiz-msft

    @Frulfump

    Yes, no worries. We will take care of it!

  11. modified the milestones: 7.4, 7.6 on Mar 12, 2026
  12. removed this from the 7.6 milestone on Mar 13, 2026
  13. zivkan commented on Mar 13, 2026

    @zivkan
    Member

    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.

  14. reopened this on Mar 13, 2026
  15. Frulfump commented on Mar 13, 2026

    @Frulfump

    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.

    Of course lol 😅. Back-compat for everything!!!

    Hope you get some time to soon 😃

  16. added this to the 7.9 milestone on May 9, 2026
  17. Frulfump commented on May 9, 2026

    @Frulfump

    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!

  18. modified the milestones: 7.9, 7.8 on Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Area:NuGetAuditBreaking-ChangeCategory:Quality WeekFunctionality:WhyPriority:2Product:dotnet.exeSeQualityType:DCR

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions