Exemple #1
0
        protected override void ProcessRecordCore()
        {
            Preprocess();

            // If Remote & Updates set of parameters are not specified, list the installed package.
            if (!UseRemoteSource)
            {
                CheckForSolutionOpen();

                Dictionary <NuGetProject, IEnumerable <PackageReference> > packagesToDisplay = GetInstalledPackages(Projects, Filter, Skip, First).Result;
                WriteInstalledPackages(packagesToDisplay);
            }
            else
            {
                if (PageSize != 0)
                {
                    _enablePaging = true;
                    First         = PageSize;
                }
                else if (First == 0)
                {
                    First = DefaultFirstValue;
                }

                if (Filter == null)
                {
                    Filter = string.Empty;
                }

                // Find avaiable packages from the current source and not taking targetframeworks into account.
                if (UseRemoteSourceOnly)
                {
                    IEnumerable <PSSearchMetadata> remotePackages = GetPackagesFromRemoteSource(Filter, Enumerable.Empty <string>(), IncludePrerelease.IsPresent, Skip, First);
                    WritePackagesFromRemoteSource(remotePackages, true);

                    if (_enablePaging)
                    {
                        WriteMoreRemotePackagesWithPaging(remotePackages);
                    }
                }
                // Get package udpates from the current source and taking targetframeworks into account.
                else
                {
                    CheckForSolutionOpen();

                    foreach (NuGetProject project in Projects)
                    {
                        IEnumerable <string>           frameworks                 = PowerShellCmdletsUtility.GetProjectTargetFrameworks(project);
                        IEnumerable <PackageReference> installedPackages          = project.GetInstalledPackagesAsync(CancellationToken.None).Result;
                        Dictionary <PSSearchMetadata, NuGetVersion> remoteUpdates = GetPackageUpdatesFromRemoteSource(installedPackages, frameworks, IncludePrerelease.IsPresent, Skip, First);
                        WriteUpdatePackagesFromRemoteSource(remoteUpdates, project);
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Output package updates to current project(s) found from the current remote source
        /// </summary>
        /// <param name="packagesToDisplay"></param>
        private async Task WriteUpdatePackagesFromRemoteSourceAsync(NuGetProject project)
        {
            var frameworks        = PowerShellCmdletsUtility.GetProjectTargetFrameworks(project);
            var installedPackages = await project.GetInstalledPackagesAsync(Token);

            VersionType versionType;

            if (CollapseVersions)
            {
                versionType = VersionType.Latest;
            }
            else
            {
                versionType = VersionType.Updates;
            }

            var projectHasUpdates = false;

            var metadataTasks = installedPackages.Select(installedPackage =>
                                                         Task.Run(async() =>
            {
                var metadata = await GetLatestPackageFromRemoteSourceAsync(installedPackage.PackageIdentity, IncludePrerelease.IsPresent);
                if (metadata != null)
                {
                    await metadata.GetVersionsAsync();
                }
                return(metadata);
            }));

            foreach (var task in installedPackages.Zip(metadataTasks, (p, t) => Tuple.Create(t, p)))
            {
                var metadata = await task.Item1;

                if (metadata != null)
                {
                    var package = PowerShellUpdatePackage.GetPowerShellPackageUpdateView(metadata, task.Item2.PackageIdentity.Version, versionType, project);

                    var versions = package.Versions ?? Enumerable.Empty <NuGetVersion>();
                    if (versions.Any())
                    {
                        projectHasUpdates = true;
                        WriteObject(package);
                    }
                }
            }

            if (!projectHasUpdates)
            {
                LogCore(ProjectManagement.MessageLevel.Info, string.Format(CultureInfo.CurrentCulture, Resources.Cmdlet_NoPackageUpdates, project.GetMetadata <string>(NuGetProjectMetadataKeys.Name)));
            }
        }