/// <summary> /// Finds all of the dependencies of a given package, including dependencies not available in the target repository. /// </summary> /// <param name="packageSearchMetadata">The package for which to obtain the dependencies for.</param> /// <param name="includeUnlisted">Include unlisted packages.</param> /// <param name="dependenciesAccumulator">A set which will contain all packages that are dependencies of the current package.</param> /// <param name="packagesNotFoundAccumulator">A set which will contain all dependencies of the package that were not found in the NuGet feed.</param> /// <param name="includePrerelease">Include pre-release packages.</param> /// <param name="token">A cancellation token to allow cancellation of the task.</param> private async Task FindDependenciesRecursiveAsync(IPackageSearchMetadata packageSearchMetadata, bool includePrerelease, bool includeUnlisted, HashSet <IPackageSearchMetadata> dependenciesAccumulator, HashSet <string> packagesNotFoundAccumulator, CancellationToken token = default) { // Check if package metadata resolved or has dependencies. if (packageSearchMetadata?.DependencySets == null) { return; } // Go over all agnostic dependency sets. foreach (var dependencySet in packageSearchMetadata.DependencySets) { foreach (var package in dependencySet.Packages) { var metadata = (await GetPackageDetails(package.Id, includePrerelease, includeUnlisted, token)).ToArray(); if (metadata.Any()) { var lastVersion = Nuget.GetNewestVersion(metadata); if (dependenciesAccumulator.Contains(lastVersion)) { continue; } dependenciesAccumulator.Add(lastVersion); await FindDependenciesRecursiveAsync(lastVersion, includePrerelease, includeUnlisted, dependenciesAccumulator, packagesNotFoundAccumulator, token); } else { packagesNotFoundAccumulator.Add(package.Id); } } } }
/// <summary> /// Finds all of the dependencies of a given package, including dependencies not available in the target repository. /// </summary> /// <param name="packageId">The package Id for which to obtain the dependencies for.</param> /// <param name="includeUnlisted">Include unlisted packages.</param> /// <param name="includePrerelease">Include pre-release packages.</param> /// <param name="token">A cancellation token to allow cancellation of the task.</param> public async Task <FindDependenciesResult> FindDependencies(string packageId, bool includePrerelease, bool includeUnlisted, CancellationToken token = default) { try { var packages = await GetPackageDetails(packageId, includePrerelease, includeUnlisted, token); return(await FindDependencies(Nuget.GetNewestVersion(packages), includePrerelease, includeUnlisted, token)); } catch (Exception) { return(new FindDependenciesResult(new HashSet <IPackageSearchMetadata>(1), new HashSet <string>(1))); } }