src/Microsoft.PackageManagement.NuGetProvider/NugetLightClient.cs
/// <summary>
/// Returns the package dependencies of packageItem. We only return the dependencies that are not installed in the destination folder of request
/// </summary>
/// <param name="packageItem"></param>
/// <param name="processedDependencies"></param>
/// <param name="request"></param>
Returns the package dependencies of packageItem. We only return the dependencies that are not installed in the destination folder of request
Returns the package dependencies of packageItem . We only return the dependencies that are not installed in the destination folder of request
private static IEnumerable<PackageItem> GetPackageDependenciesHelper(PackageItem packageItem, HashSet<string> processedDependencies, NuGetRequest request)
        {
            if (packageItem.Package.DependencySetList == null)
            {
                yield break;
            }
            bool force = request.GetOptionValue("Force") != null;
            foreach (var depSet in packageItem.Package.DependencySetList)
            {
                if (depSet.Dependencies == null)
                {
                    continue;
                }
                foreach (var dep in depSet.Dependencies)
                {
                    var depKey = string.Format(CultureInfo.InvariantCulture, "{0}!#!{1}", dep.Id, dep.DependencyVersion.ToStringSafe());
                    if (processedDependencies.Contains(depKey))
                    {
                        continue;
                    }
                    string minVersion = dep.DependencyVersion.MinVersion.ToStringSafe();
                    string maxVersion = dep.DependencyVersion.MaxVersion.ToStringSafe();
                    if (!force)
                    {
                        bool installed = false;
                        var installedPackages = request.InstalledPackages.Value;
                        if (request.InstalledPackages.Value.Count() > 0)
                        {
                            foreach (var installedPackage in request.InstalledPackages.Value)
                            {
                                if (!string.Equals(installedPackage.Id, dep.Id, StringComparison.OrdinalIgnoreCase))
                                {
                                    continue;
                                }
                                if (string.IsNullOrWhiteSpace(installedPackage.Version))
                                {
                                    installed = true;
                                    break;
                                }
                                SemanticVersion packageVersion = new SemanticVersion(installedPackage.Version);
                                if (request.MinAndMaxVersionMatched(packageVersion, minVersion, maxVersion, dep.DependencyVersion.IsMinInclusive, dep.DependencyVersion.IsMaxInclusive))
                                {
                                    installed = true;
                                    break;
                                }
                            }
                        }
                        else if (request.GetInstalledPackages(dep.Id, null, minVersion, maxVersion, minInclusive: dep.DependencyVersion.IsMinInclusive, maxInclusive: dep.DependencyVersion.IsMaxInclusive, terminateFirstFound: true))
                        {
                            installed = true;
                        }
                        if (installed)
                        {
                            processedDependencies.Add(dep.Id);
                            request.Verbose(String.Format(CultureInfo.CurrentCulture, Messages.AlreadyInstalled, dep.Id));
                            continue;
                        }
                    }
                    var dependentPackageItem = request.GetPackageById(dep.Id, request, minimumVersion: minVersion, maximumVersion: maxVersion, minInclusive: dep.DependencyVersion.IsMinInclusive, maxInclusive: dep.DependencyVersion.IsMaxInclusive).ToArray();
                    if (dependentPackageItem.Length == 0)
                    {
                        request.WriteError(ErrorCategory.ObjectNotFound, dep.Id, Constants.Messages.UnableToFindDependencyPackage, dep.Id);
                        break;
                    }
                    yield return dependentPackageItem.OrderByDescending(each => each.Version).FirstOrDefault();
                    processedDependencies.Add(depKey);
                }
            }
        }
private static IEnumerable < PackageItem > GetPackageDependenciesHelper ( PackageItem packageItem , HashSet < string > processedDependencies , NuGetRequest request ) { if ( packageItem . Package . DependencySetList == null ) { yield break ; } bool force = request . GetOptionValue ( " " ) != null ; foreach ( var depSet in packageItem . Package . DependencySetList ) { if ( depSet . Dependencies == null ) { continue ; } foreach ( var dep in depSet . Dependencies ) { var depKey = string . Format ( CultureInfo . InvariantCulture , " " , dep . Id , dep . DependencyVersion . ToStringSafe ( ) ) ; if ( processedDependencies . Contains ( depKey ) ) { continue ; } string minVersion = dep . DependencyVersion . MinVersion . ToStringSafe ( ) ; string maxVersion = dep . DependencyVersion . MaxVersion . ToStringSafe ( ) ; if ( ! force ) { bool installed = false ; var installedPackages = request . InstalledPackages . Value ; if ( request . InstalledPackages . Value . Count ( ) > 0 ) { foreach ( var installedPackage in request . InstalledPackages . Value ) { if ( ! string . Equals ( installedPackage . Id , dep . Id , StringComparison . OrdinalIgnoreCase ) ) { continue ; } if ( string . IsNullOrWhiteSpace ( installedPackage . Version ) ) { installed = true ; break ; } SemanticVersion packageVersion = new SemanticVersion ( installedPackage . Version ) ; if ( request . MinAndMaxVersionMatched ( packageVersion , minVersion , maxVersion , dep . DependencyVersion . IsMinInclusive , dep . DependencyVersion . IsMaxInclusive ) ) { installed = true ; break ; } } } else if ( request . GetInstalledPackages ( dep . Id , null , minVersion , maxVersion , minInclusive : dep . DependencyVersion . IsMinInclusive , maxInclusive : dep . DependencyVersion . IsMaxInclusive , terminateFirstFound : true ) ) { installed = true ; } if ( installed ) { processedDependencies . Add ( dep . Id ) ; request . Verbose ( String . Format ( CultureInfo . CurrentCulture , Messages . AlreadyInstalled , dep . Id ) ) ; continue ; } } var dependentPackageItem = request . GetPackageById ( dep . Id , request , minimumVersion : minVersion , maximumVersion : maxVersion , minInclusive : dep . DependencyVersion . IsMinInclusive , maxInclusive : dep . DependencyVersion . IsMaxInclusive ) . ToArray ( ) ; if ( dependentPackageItem . Length == 0 ) { request . WriteError ( ErrorCategory . ObjectNotFound , dep . Id , Constants . Messages . UnableToFindDependencyPackage , dep . Id ) ; break ; } yield return dependentPackageItem . OrderByDescending ( each => each . Version ) . FirstOrDefault ( ) ; processedDependencies . Add ( depKey ) ; } } }
Returns the package dependencies of packageItem.
Returns the package dependencies of packageItem .
// Get the min dependencies version // Get the max dependencies version // check the installedpackages options passed in // if name not match, move on to the next entry // if no version and if name matches, skip // skip this dependency // checks min and max // skip this dependency // check whether package is installed at destination. only used this option if installedpackages not passed in // already processed this so don't need to do this next time // already have a dependency so move on // get all the packages that match this dependency // Get the package that is the latest version
packageItem
PackageItem
None
processedDependencies
HashSet<string>
None
request
NuGetRequest
None