// This gets called for every package install, including dependencies, and is our only chance to handle dependency PackageIdentity instances
 public override Task <bool> InstallPackageAsync(PackageIdentity packageIdentity, DownloadResourceResult downloadResourceResult,
                                                 INuGetProjectContext nuGetProjectContext, CancellationToken token)
 {
     _installedPackages.AddPackage(packageIdentity, _currentFramework);
     Trace.Verbose($"Installing package or dependency {packageIdentity.Id} {(packageIdentity.HasVersion ? packageIdentity.Version.ToNormalizedString() : string.Empty)}");
     return(base.InstallPackageAsync(packageIdentity, downloadResourceResult, nuGetProjectContext, token));
 }
Beispiel #2
0
        public async Task Install(IReadOnlyList <SourceRepository> remoteRepositories, InstalledPackagesCache installedPackages, NuGetPackageManager packageManager)
        {
            if (_versionMatch == null)
            {
                return;
            }
            IReadOnlyList <SourceRepository> sourceRepositories = GetSourceRepositories(remoteRepositories);

            using (Trace.WithIndent().Verbose($"Installing package {_packageId} {_versionMatch.ToNormalizedString()}"))
            {
                // Check if this package was already installed in a previous run
                PackageIdentity packageIdentity = new PackageIdentity(_packageId, _versionMatch);
                if (installedPackages.VerifyPackage(packageIdentity, packageManager))
                {
                    Trace.Verbose($"Package {_packageId} {_versionMatch.ToNormalizedString()} was already installed");
                    return;
                }

                // If not, go ahead and install it
                using (installedPackages.AddPackage(packageIdentity, _currentFramework))
                {
                    ResolutionContext resolutionContext = new ResolutionContext(
                        DependencyBehavior.Lowest, _allowPrereleaseVersions, _allowUnlisted, VersionConstraints.None);
                    INuGetProjectContext projectContext = new NuGetProjectContext();
                    await packageManager.InstallPackageAsync(packageManager.PackagesFolderNuGetProject,
                                                             packageIdentity, resolutionContext, projectContext,
                                                             sourceRepositories, Array.Empty <SourceRepository>(), CancellationToken.None);

                    Trace.Verbose($"Installed package {_packageId} {_versionMatch.ToNormalizedString()}");
                }
            }
        }