Esempio n. 1
0
        internal IEnumerable <PackageItem> GetUninstalledPackageDependencies(PackageItem packageItem)
        {
            foreach (var depSet in packageItem.Package.DependencySets)
            {
                foreach (var dep in depSet.Dependencies)
                {
                    // get all the packages that match this dependency
                    var depRefs = dep.VersionSpec == null?GetPackageById(dep.Id).ToArray() : GetPackageByIdAndVersionSpec(dep.Id, dep.VersionSpec, true).ToArray();

                    if (depRefs.Length == 0)
                    {
                        Error(ErrorCategory.ObjectNotFound, packageItem.GetCanonicalId(this), Constants.Messages.DependencyResolutionError, GetCanonicalPackageId(ProviderName, dep.Id, ((object)dep.VersionSpec ?? "").ToString()));
                        throw new Exception("failed");
                    }

                    if (depRefs.Any(each => IsPackageInstalled(each.Id, each.Version)))
                    {
                        // we have a compatible version installed.
                        continue;
                    }

                    yield return(depRefs[0]);

                    // it's not installed. return this as a needed package, but first, get it's dependencies.
                    foreach (var nestedDep in GetUninstalledPackageDependencies(depRefs[0]))
                    {
                        yield return(nestedDep);
                    }
                }
            }
        }
Esempio n. 2
0
        internal bool InstallSinglePackage(PackageItem packageItem)
        {
            // Get NuGet to install the Package
            PreInstall(packageItem);
            var results = NuGetInstall(packageItem);

            if (results.Status == InstallStatus.Successful)
            {
                foreach (var installedPackage in results[InstallStatus.Successful])
                {
                    if (!NotifyPackageInstalled(installedPackage.Id, installedPackage.Version, installedPackage.PackageSource.Name, installedPackage.FullPath))
                    {
                        // the caller has expressed that they are cancelling the install.
                        Verbose("NotifyPackageInstalled returned false--This is unexpected");
                        // todo: we should probablty uninstall this package unless the user said leave broken stuff behind
                        return(false);
                    }

                    // run any extra steps
                    if (!PostInstall(installedPackage))
                    {
                        // package failed installation. uninstall it.
                        UninstallPackage(installedPackage);

                        return(false);
                    }

                    YieldPackage(packageItem, packageItem.PackageSource.Name);
                    // yay!
                }
                return(true);
            }

            if (results.Status == InstallStatus.AlreadyPresent)
            {
                // hmm Weird.
                Verbose("Skipped Package '{0} v{1}' already installed", packageItem.Id, packageItem.Version);
                return(true);
            }

            Error(ErrorCategory.InvalidResult, packageItem.GetCanonicalId(this), MultiplePackagesInstalledExpectedOne, packageItem.GetCanonicalId(this));

            return(false);
        }