Beispiel #1
0
        public override Task InstallPackage(
            PackageIdentity id,
            IEnumerable <FrameworkName> packageSupportedFrameworks,
            IExecutionLogger logger,
            CancellationToken cancelToken)
        {
            var args = new Dictionary <string, object>();
            var projectFrameworks = _nugetAwareProject.GetSupportedFrameworksAsync(cancelToken).Result;

            args["Frameworks"] = projectFrameworks.Where(
                projectFramework =>
                NuGet.VersionUtility.IsCompatible(
                    projectFramework,
                    packageSupportedFrameworks)).ToArray();
            var task = _nugetAwareProject.InstallPackageAsync(
                new NuGetPackageMoniker
            {
                Id      = id.Id,
                Version = id.Version.ToString()
            },
                args,
                logger: null,
                progress: null,
                cancellationToken: cancelToken);

            return(task);
        }
Beispiel #2
0
        private void AddPackageReferenceToNuGetAwareProject(IPackage package)
        {
            INuGetPackageManager        project = this.Project as INuGetPackageManager;
            Dictionary <string, object> options = new Dictionary <string, object>();

            using (CancellationTokenSource source = new CancellationTokenSource())
            {
                IEnumerable <FrameworkName>         packageSupportedFrameworks = package.GetSupportedFrameworks();
                IReadOnlyCollection <FrameworkName> result = project.GetSupportedFrameworksAsync(source.Token).Result;
                options["Frameworks"] = (from projectFramework in result
                                         where VersionUtility.IsCompatible(projectFramework, packageSupportedFrameworks)
                                         select projectFramework).ToArray <FrameworkName>();
                NuGetPackageMoniker moniker1 = new NuGetPackageMoniker();
                moniker1.Id      = package.Id;
                moniker1.Version = package.Version.ToString();
                project.InstallPackageAsync(moniker1, options, null, null, source.Token).Wait();
            }
        }
        public override async Task <bool> InstallPackageAsync(
            PackageIdentity packageIdentity,
            DownloadResourceResult downloadResourceResult,
            INuGetProjectContext nuGetProjectContext,
            CancellationToken token)
        {
            if (downloadResourceResult == null)
            {
                throw new ArgumentNullException(nameof(downloadResourceResult));
            }

            var packageStream = downloadResourceResult.PackageStream;

            if (!packageStream.CanSeek)
            {
                throw new ArgumentException(ProjectManagement.Strings.PackageStreamShouldBeSeekable);
            }

            nuGetProjectContext.Log(ProjectManagement.MessageLevel.Info, Strings.InstallingPackage, packageIdentity);

            packageStream.Seek(0, SeekOrigin.Begin);
            var packageSupportedFrameworks = GetSupportedFrameworks(packageStream);
            var projectFrameworks          = _project.GetSupportedFrameworksAsync(token)
                                             .Result
                                             .Select(f => NuGetFramework.Parse(f.FullName));

            var args = new Dictionary <string, object>();

            args["Frameworks"] = projectFrameworks.Where(
                projectFramework =>
                IsCompatible(projectFramework, packageSupportedFrameworks)).ToArray();
            await _project.InstallPackageAsync(
                new NuGetPackageMoniker
            {
                Id      = packageIdentity.Id,
                Version = packageIdentity.Version.ToNormalizedString()
            },
                args,
                logger : null,
                progress : null,
                cancellationToken : token);

            return(true);
        }
Beispiel #4
0
        public async override Task <bool> InstallPackageAsync(Packaging.Core.PackageIdentity packageIdentity, System.IO.Stream packageStream,
                                                              INuGetProjectContext nuGetProjectContext, CancellationToken token)
        {
            if (!packageStream.CanSeek)
            {
                throw new ArgumentException(NuGet.ProjectManagement.Strings.PackageStreamShouldBeSeekable);
            }

            nuGetProjectContext.Log(MessageLevel.Info, Strings.InstallingPackage, packageIdentity);

            packageStream.Seek(0, SeekOrigin.Begin);
            var           zipArchive    = new ZipArchive(packageStream);
            PackageReader packageReader = new PackageReader(zipArchive);
            var           packageSupportedFrameworks = packageReader.GetSupportedFrameworks();
            var           projectFrameworks          = _project.GetSupportedFrameworksAsync(token)
                                                       .Result
                                                       .Select(f => NuGetFramework.Parse(f.FullName));

            var args = new Dictionary <string, object>();

            args["Frameworks"] = projectFrameworks.Where(
                projectFramework =>
                IsCompatible(projectFramework, packageSupportedFrameworks)).ToArray();
            await _project.InstallPackageAsync(
                new NuGetPackageMoniker
            {
                Id      = packageIdentity.Id,
                Version = packageIdentity.Version.ToNormalizedString()
            },
                args,
                logger : null,
                progress : null,
                cancellationToken : token);

            return(true);
        }
Beispiel #5
0
        public override async Task <bool> InstallPackageAsync(
            PackageIdentity packageIdentity,
            DownloadResourceResult downloadResourceResult,
            INuGetProjectContext nuGetProjectContext,
            CancellationToken token)
        {
            if (downloadResourceResult == null)
            {
                throw new ArgumentNullException(nameof(downloadResourceResult));
            }

            var packageStream = downloadResourceResult.PackageStream;

            if (!packageStream.CanSeek)
            {
                throw new ArgumentException(Strings.PackageStreamShouldBeSeekable);
            }

            // Uninstall the package if it is already installed. This should only happen when an
            // update occurred from Install-Package PMC command, the Browse tab in the UI, or the
            // Installed tab in the UI. An update from the Updates tab has an explicit Uninstall
            // action before the install.
            var installedPackages = await GetInstalledPackagesAsync(token);

            var packageToReplace = installedPackages
                                   .Where(pr => StringComparer.OrdinalIgnoreCase.Equals(pr.PackageIdentity.Id, packageIdentity.Id))
                                   .FirstOrDefault();

            if (packageToReplace != null)
            {
                await UninstallPackageAsync(packageToReplace.PackageIdentity, nuGetProjectContext, token);
            }

            nuGetProjectContext.Log(MessageLevel.Info, Strings.InstallingPackage, packageIdentity);

            // Get additional information from the package that the INuGetPackageManager can act on.
            packageStream.Seek(0, SeekOrigin.Begin);

            IEnumerable <NuGetFramework> supportedFrameworks;
            IEnumerable <PackageType>    packageTypes;

            using (var packageReader = new PackageArchiveReader(packageStream, leaveStreamOpen: true))
            {
                supportedFrameworks = packageReader.GetSupportedFrameworks();
                packageTypes        = packageReader.GetPackageTypes();
            }

            var args = new Dictionary <string, object>();

            args["Frameworks"] = supportedFrameworks
                                 .Where(f => f.IsSpecificFramework)
                                 .ToArray();

            args["PackageTypes"] = packageTypes
                                   .ToArray();

            object state;

            if (_packageUpdateState.TryGetValue(packageIdentity.Id, out state))
            {
                args[StateKey] = state;
            }

            // Perform the actual installation by delegating to INuGetPackageManager.
            await _project.InstallPackageAsync(
                new NuGetPackageMoniker
            {
                Id      = packageIdentity.Id,
                Version = packageIdentity.Version.ToNormalizedString()
            },
                args,
                logger : null,
                progress : null,
                cancellationToken : token);

            return(true);
        }
 public Task InstallPackageAsync(INuGetPackageMoniker package, IReadOnlyDictionary <string, object> options, System.IO.TextWriter logger, IProgress <INuGetPackageInstallProgress> progress, CancellationToken cancellationToken)
 {
     return(_nugetProject.InstallPackageAsync(package, options, logger, progress, cancellationToken));
 }