Is there a way, either textual or graphical, to view the hierarchy of dependencies between NuGet packages?
To add a dependency, either add a package through the Package Manager UI or Console in Visual Studio, or modify packages. config and then run either install or restore . Open a command line and switch to the directory that contains your project file.
Any time a package is installed or reinstalled, which includes being installed as part of a restore process, NuGet also installs any additional packages on which that first package depends. Those immediate dependencies might then also have dependencies on their own, which can continue to an arbitrary depth.
On the Project menu, choose Project Dependencies. The Project Dependencies dialog box opens. On the Dependencies tab, select a project from the Project drop-down menu. In the Depends on field, select the check box of any other project that must build before this project does.
Like @neil-barnwell solution, but works with NuGet.Core 2.7+
Install-Package NuGet.Core
Here is the code
using System; using System.Linq; using System.Runtime.Versioning; using System.IO; using NuGet; public class Program { public static void Main(string[] args) { var frameworkName = new FrameworkName(".NETFramework, Version=4.0"); // var packageSource = "https://www.nuget.org/api/v2/"; var packageSource = Path.Combine(Environment.GetEnvironmentVariable("LocalAppData"), "NuGet", "Cache"); var repository = PackageRepositoryFactory.Default.CreateRepository(packageSource); const bool prerelease = false; var packages = repository.GetPackages() .Where(p => prerelease ? p.IsAbsoluteLatestVersion : p.IsLatestVersion) .Where(p => VersionUtility.IsCompatible(frameworkName, p.GetSupportedFrameworks())); foreach (IPackage package in packages) { GetValue(repository, frameworkName, package, prerelease, 0); } Console.WriteLine(); Console.WriteLine("Press Enter..."); Console.ReadLine(); } private static void GetValue(IPackageRepository repository, FrameworkName frameworkName, IPackage package, bool prerelease, int level) { Console.WriteLine("{0}{1}", new string(' ', level * 3), package); foreach (PackageDependency dependency in package.GetCompatiblePackageDependencies(frameworkName)) { IPackage subPackage = repository.ResolveDependency(dependency, prerelease, true); GetValue(repository, frameworkName, subPackage, prerelease, level + 1); } } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With