View NuGet package dependency hierarchy

后端 未结 10 1291
遇见更好的自我
遇见更好的自我 2020-12-07 16:24

Is there a way, either textual or graphical, to view the hierarchy of dependencies between NuGet packages?

相关标签:
10条回答
  • 2020-12-07 17:07

    I Can Has .NET Core (GitHub repository) produces nice graphs of NuGet dependencies along with a Graphviz representation. And as its name implies, you also get .NET Core compatibility information for free.

    If you prefer to run it locally on your computer, I Can Has .NET Core also offers a console mode.

    0 讨论(0)
  • 2020-12-07 17:10

    I add a compatible solution with the latest version of nuget-core

    install-package nuget.core
    

    This is the console App to get the dependencies graph

        class Program
        {
            static void Main()
            {
                Console.Write("Enter the local repo folder: ");
                var repoFolder = Console.ReadLine();
    
                var repo = new LocalPackageRepository(repoFolder);
                IQueryable<IPackage> packages = repo.GetPackages();
                OutputGraph(repo, packages, 0);
            }
    
            static void OutputGraph(LocalPackageRepository repository, IEnumerable<IPackage> packages, int depth)
            {
                foreach (IPackage package in packages)
                {
                    Console.WriteLine("{0}{1} v{2}", new string(' ', depth), package.Id, package.Version);
    
                    IList<IPackage> dependentPackages = new List<IPackage>();
                    foreach (var dependencySet in package.DependencySets)
                    {
                        foreach (var dependency in dependencySet.Dependencies)
                        {
                            var dependentPackage = repository.FindPackage(dependency.Id, dependency.VersionSpec, true, true);
                            if (dependentPackage != null)
                            {
                                dependentPackages.Add(dependentPackage);
                            }
                        }       
                    }
    
                    OutputGraph(repository, dependentPackages, depth += 3);
                }
            }
        }
    
    0 讨论(0)
  • 2020-12-07 17:12

    I've found a nice NPM package to print the dependency tree into console. Of course if you don't mind using/installing NPM/Node.JS.

    Considering other solutions, this is the most simple one, you don't need to write your own code or register something, and you get just such dependency tree as you expect. But it works only with packages.config format.

    I can't believe this functionality is absent in free Visual Studio editions or nuget.exe too.

    0 讨论(0)
  • 2020-12-07 17:13

    https://github.com/mikehadlow/AsmSpy using this to identify assembly version across a project

    0 讨论(0)
提交回复
热议问题