Ejemplo n.º 1
0
        // Updates the specified package in projects
        private IEnumerable <Resolver.PackageAction> ResolveActionsToUpdateOnePackage(string id, SemanticVersion version, IEnumerable <IProjectManager> projectManagers,
                                                                                      bool projectNameSpecified)
        {
            var packageManager = projectManagers.First().PackageManager;
            var oldPackage     = projectNameSpecified ?
                                 FindPackageToUpdate(id, version, packageManager, projectManagers.First()) :
                                 FindPackageToUpdate(id, version, packageManager, projectManagers, Logger);

            if (oldPackage.Item2 == null)
            {
                // we're updating a solution level package
                var package = packageManager.SourceRepository.FindPackage(
                    id, version, AllowPrereleaseVersions, allowUnlisted: false);
                if (package == null)
                {
                    Logger.Log(MessageLevel.Info, VsResources.NoUpdatesAvailable, id);
                    return(Enumerable.Empty <Resolver.PackageAction>());
                }

                Resolver.AddOperation(PackageAction.Update, package, new NullProjectManager(packageManager));
            }
            else
            {
                AddUpdateOperations(
                    id,
                    version,
                    projectManagers);
            }

            return(Resolver.ResolveActions());
        }
Ejemplo n.º 2
0
        void AddUnsafeUpdateOperation(
            string id,
            SemanticVersion version,
            bool targetVersionSetExplicitly,
            IProjectManager projectManager)
        {
            var oldPackage = projectManager.LocalRepository.FindPackage(id);

            if (oldPackage == null)
            {
                return;
            }

            Logger.Log(MessageLevel.Debug, NuGetResources.Debug_LookingForUpdates, id);

            var package = projectManager.PackageManager.SourceRepository.FindPackage(
                id, version,
                projectManager.ConstraintProvider,
                AllowPrereleaseVersions,
                allowUnlisted: false);

            // the condition (allowPrereleaseVersions || targetVersionSetExplicitly || oldPackage.IsReleaseVersion() || !package.IsReleaseVersion() || oldPackage.Version < package.Version)
            // is to fix bug 1574. We want to do nothing if, let's say, you have package 2.0alpha installed, and you do:
            //      update-package
            // without specifying a version explicitly, and the feed only has version 1.0 as the latest stable version.
            if (package != null &&
                oldPackage.Version != package.Version &&
                (AllowPrereleaseVersions || targetVersionSetExplicitly || oldPackage.IsReleaseVersion() || !package.IsReleaseVersion() ||
                 oldPackage.Version < package.Version))
            {
                Logger.Log(MessageLevel.Info, NuGetResources.Log_UpdatingPackages,
                           package.Id,
                           oldPackage.Version,
                           package.Version,
                           projectManager.Project.ProjectName);

                Resolver.AddOperation(PackageAction.Install, package, projectManager);
            }
            else
            {
                throw new Exception(String.Format(NuGetResources.InvalidVersionString, version.ToString()));
            }

            // Display message that no updates are available.
            IVersionSpec constraint = projectManager.ConstraintProvider.GetConstraint(package.Id);

            if (constraint != null)
            {
                Logger.Log(MessageLevel.Info, NuGetResources.Log_ApplyingConstraints, package.Id, VersionUtility.PrettyPrint(constraint),
                           projectManager.ConstraintProvider.Source);
            }

            Logger.Log(
                MessageLevel.Info,
                NuGetResources.Log_NoUpdatesAvailableForProject,
                package.Id,
                projectManager.Project.ProjectName);
        }
Ejemplo n.º 3
0
        void AddUnsafeUpdateOperation(
            string id,
            SemanticVersion version,
            bool targetVersionSetExplicitly,
            IProjectManager projectManager)
        {
            Logger.Log(MessageLevel.Debug, NuGetResources.Debug_LookingForUpdates, id);

            var package = projectManager.PackageManager.SourceRepository.FindPackage(
                id, version,
                projectManager.ConstraintProvider,
                AllowPrereleaseVersions,
                allowUnlisted: false);

            if (package != null)
            {
                Logger.Log(MessageLevel.Info, NuGetResources.Log_UpdatingPackages,
                           package.Id,
                           package.Version,
                           projectManager.Project.ProjectName);

                Resolver.AddOperation(PackageAction.Install, package, projectManager);
            }
            else
            {
                throw new Exception(String.Format(NuGetResources.InvalidVersionString, version.ToString()));
            }

            // Display message that no updates are available.
            IVersionSpec constraint = projectManager.ConstraintProvider.GetConstraint(package.Id);

            if (constraint != null)
            {
                Logger.Log(MessageLevel.Info, NuGetResources.Log_ApplyingConstraints, package.Id, VersionUtility.PrettyPrint(constraint),
                           projectManager.ConstraintProvider.Source);
            }

            Logger.Log(
                MessageLevel.Info,
                NuGetResources.Log_NoUpdatesAvailableForProject,
                package.Id,
                projectManager.Project.ProjectName);
        }
Ejemplo n.º 4
0
        // Add update operations to the resolver
        private void AddUpdateOperations(
            string id,
            SemanticVersion version,
            IEnumerable <IProjectManager> projectManagers)
        {
            if (!Safe)
            {
                // Update to latest version
                foreach (var projectManager in projectManagers)
                {
                    AddUnsafeUpdateOperation(
                        id,
                        version,
                        version != null,
                        projectManager);
                }
            }
            else
            {
                // safe update
                foreach (var projectManager in projectManagers)
                {
                    IPackage installedPackage = projectManager.LocalRepository.FindPackage(id);
                    if (installedPackage == null)
                    {
                        continue;
                    }

                    var safeRange = VersionUtility.GetSafeRange(installedPackage.Version);
                    var package   = projectManager.PackageManager.SourceRepository.FindPackage(
                        id,
                        safeRange,
                        projectManager.ConstraintProvider,
                        AllowPrereleaseVersions,
                        allowUnlisted: false);

                    Resolver.AddOperation(PackageAction.Install, package, projectManager);
                }
            }
        }