ramosisw/dotnet-nuget-tree

Tool fails if a project uses CentralPackageVersionManagement nuget feature

Opened this issue · 2 comments

If a project uses such feature, the tool crashes.
image

Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at dotnet.nuget.tree.Command.OptionsCommand.<>c.<GetPackages>b__33_0(XElement e) in S:\any\dotnet-nuget-tree\src\Command\OptionsCommand.cs:line 131
   at System.Linq.Enumerable.SelectEnumerableIterator`2.ToList()
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at dotnet.nuget.tree.Command.OptionsCommand.GetPackages(String fullProjectPath) in S:\any\dotnet-nuget-tree\src\Command\OptionsCommand.cs:line 127
   at dotnet.nuget.tree.Command.OptionsCommand.Parse(String[] args) in S:\any\dotnet-nuget-tree\src\Command\OptionsCommand.cs:line 88
   at dotnet.nuget.tree.Program.Main(String[] args) in S:\any\dotnet-nuget-tree\src\Program.cs:line 42
   at dotnet.nuget.tree.Program.<Main>(String[] args)

Directory.Packages.props

<Project>
  <PropertyGroup>
    <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
  </PropertyGroup>
  <ItemGroup>
    <PackageVersion Include="Newtonsoft.Json" Version="13.0.1" />
  </ItemGroup>
</Project>

Project.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" />
  </ItemGroup>
</Project>

https://devblogs.microsoft.com/nuget/introducing-central-package-management/

This tool was created to help you find libraries that are not compatible between nugets during a framework upgrade, for example, nuget C used in nugets A and B is not compatible and the build log only tells you that an inferior version of library C was detected and does not indicate who uses said library.

The .NET team has already developed something similar that I think is better by giving options such as which libraries you can update, which ones are obsolete or incompatible.

https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-list-package

The .NET team has already developed something similar that I think is better by giving options such as which libraries you can update, which ones are obsolete or incompatible.

https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-list-package

Problem is, it's a flattened list. To get a tree you can use https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-nuget-why. However, that only works for specific packages, so you can't get the entire dependency tree.

I listed some more options here (didn't include this project because I couldn't validate it works due to the above issue): https://stackoverflow.com/a/79062868/67824