Example #1
0
        private void AddUnsafeUpdateOperation(string id, SemanticVersion version, bool targetVersionSetExplicitly, IProjectManager projectManager)
        {
            IPackage packageMetadata = projectManager.LocalRepository.FindPackage(id);

            if (packageMetadata != null)
            {
                object[] args = new object[] { id };
                this.Logger.Log(MessageLevel.Debug, NuGetResources.Debug_LookingForUpdates, args);
                IPackage package2 = projectManager.PackageManager.SourceRepository.FindPackage(id, version, projectManager.ConstraintProvider, this.AllowPrereleaseVersions, false);
                if ((package2 != null) && ((packageMetadata.Version != package2.Version) && ((this.AllowPrereleaseVersions | targetVersionSetExplicitly) || (packageMetadata.IsReleaseVersion() || (!package2.IsReleaseVersion() || (packageMetadata.Version < package2.Version))))))
                {
                    object[] objArray2 = new object[] { package2.Id, packageMetadata.Version, package2.Version, projectManager.Project.ProjectName };
                    this.Logger.Log(MessageLevel.Info, NuGetResources.Log_UpdatingPackages, objArray2);
                    this.Resolver.AddOperation(PackageAction.Install, package2, projectManager);
                }
                IVersionSpec constraint = projectManager.ConstraintProvider.GetConstraint(package2.Id);
                if (constraint != null)
                {
                    object[] objArray3 = new object[] { package2.Id, VersionUtility.PrettyPrint(constraint), projectManager.ConstraintProvider.Source };
                    this.Logger.Log(MessageLevel.Info, NuGetResources.Log_ApplyingConstraints, objArray3);
                }
                object[] objArray4 = new object[] { package2.Id, projectManager.Project.ProjectName };
                this.Logger.Log(MessageLevel.Info, NuGetResources.Log_NoUpdatesAvailableForProject, objArray4);
            }
        }
Example #2
0
        public override string ToString()
        {
            if (VersionSpec == null)
            {
                return(Id);
            }

            return(Id + " " + VersionUtility.PrettyPrint(VersionSpec));
        }
Example #3
0
        protected override void OnDependencyResolveError(PackageDependency dependency)
        {
            IVersionSpec constraint = this.ConstraintProvider.GetConstraint(dependency.Id);
            string       str        = string.Empty;

            if (constraint != null)
            {
                object[] objArray1 = new object[] { dependency.Id, VersionUtility.PrettyPrint(constraint), this.ConstraintProvider.Source };
                str = string.Format(CultureInfo.CurrentCulture, NuGetResources.AdditonalConstraintsDefined, objArray1);
            }
            object[] args = new object[] { dependency };
            throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, NuGetResources.UnableToResolveDependency + str, args));
        }
Example #4
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);
        }
Example #5
0
        protected override void OnDependencyResolveError(PackageDependency dependency)
        {
            IVersionSpec spec = ConstraintProvider.GetConstraint(dependency.Id);

            string message = String.Empty;

            if (spec != null)
            {
                message = String.Format(CultureInfo.CurrentCulture, NuGetResources.AdditonalConstraintsDefined, dependency.Id, VersionUtility.PrettyPrint(spec), ConstraintProvider.Source);
            }

            throw new InvalidOperationException(
                      String.Format(CultureInfo.CurrentCulture,
                                    NuGetResources.UnableToResolveDependency + message, dependency));
        }
Example #6
0
        private void UpdatePackageReference(string packageId, Func <IPackage> resolvePackage, bool updateDependencies, bool allowPrereleaseVersions, bool targetVersionSetExplicitly)
        {
            if (String.IsNullOrEmpty(packageId))
            {
                throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "packageId");
            }

            IPackage oldPackage = LocalRepository.FindPackage(packageId);

            // Check to see if this package is installed
            if (oldPackage == null)
            {
                throw new InvalidOperationException(
                          String.Format(CultureInfo.CurrentCulture,
                                        NuGetResources.ProjectDoesNotHaveReference, Project.ProjectName, packageId));
            }

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

            IPackage package = resolvePackage();

            // 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, Project.ProjectName);
                UpdatePackageReference(package, updateDependencies, allowPrereleaseVersions);
            }
            else
            {
                IVersionSpec constraint = ConstraintProvider.GetConstraint(packageId);
                if (constraint != null)
                {
                    Logger.Log(MessageLevel.Info, NuGetResources.Log_ApplyingConstraints, packageId, VersionUtility.PrettyPrint(constraint), ConstraintProvider.Source);
                }

                Logger.Log(MessageLevel.Info, NuGetResources.Log_NoUpdatesAvailableForProject, packageId, Project.ProjectName);
            }
        }
Example #7
0
 public override string ToString() =>
 ((this.VersionSpec != null) ? (this.Id + " " + VersionUtility.PrettyPrint(this.VersionSpec)) : this.Id);
        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);
        }