Example #1
0
        private void Uninstall(IPackage package, IDependentsResolver dependentsResolver, IPackageRepository repository)
        {
            // If this package isn't part of the current graph (i.e. hasn't been visited yet) and
            // is marked for removal, then do nothing. This is so we don't get unnecessary duplicates.
            if (!Marker.Contains(package) && _operations.Contains(package, PackageAction.Uninstall))
            {
                return;
            }

            // Uninstall the conflicting package. We set throw on conflicts to false since we've
            // already decided that there were no conflicts based on the above code.
            var resolver = new UninstallWalker(repository,
                                               dependentsResolver,
                                               TargetFramework,
                                               NullLogger.Instance,
                                               removeDependencies: !IgnoreDependencies,
                                               forceRemove: false)
            {
                ThrowOnConflicts = false
            };

            foreach (var operation in resolver.ResolveOperations(package))
            {
                _operations.AddOperation(operation);
            }
        }
Example #2
0
        private void Uninstall(IPackage package, IDependentsResolver dependentsResolver, IPackageRepository repository)
        {
            // If we explicitly want to uninstall this package, then remove it from the retainment queue.
            _packagesToKeep.Remove(package);

            // If this package isn't part of the current graph (i.e. hasn't been visited yet) and
            // is marked for removal, then do nothing. This is so we don't get unnecessary duplicates.
            if (!Marker.Contains(package) && _operations.Contains(package, PackageAction.Uninstall))
            {
                return;
            }

            // Uninstall the conflicting package. We set throw on conflicts to false since we've
            // already decided that there were no conflicts based on the above code.
            var resolver = new UninstallWalker(
                repository,
                dependentsResolver,
                TargetFramework,
                NullLogger.Instance,
                removeDependencies: !IgnoreDependencies,
                forceRemove: false)
            {
                DisableWalkInfo  = this.DisableWalkInfo,
                ThrowOnConflicts = false
            };

            foreach (var operation in resolver.ResolveOperations(package))
            {
                // If the operation is Uninstall, we don't want to uninstall the package if it is in the "retainment" queue.
                if (operation.Action == PackageAction.Install || !_packagesToKeep.Contains(operation.Package))
                {
                    _operations.AddOperation(operation);
                }
            }
        }
Example #3
0
        private bool IsConnected(IPackage package)
        {
            // We could cache the results of this lookup
            if (Marker.Contains(package))
            {
                return(true);
            }

            IEnumerable <IPackage> dependents = DependentsResolver.GetDependents(package);

            return(dependents.Any() && dependents.All(IsConnected));
        }
Example #4
0
        public override void Add(Marker marker)
        {
            if (marker == null)
            {
                throw new ArgumentNullException(nameof(marker));
            }

            if (Contains(marker) || marker.Contains(this))
            {
                return;
            }
            _referenceList.Add(marker);
        }
Example #5
0
        protected override void OnBeforePackageWalk(IPackage package)
        {
            ConflictResult conflictResult = GetConflict(package.Id);

            if (conflictResult == null)
            {
                return;
            }

            // If the conflicting package is the same as the package being installed
            // then no-op
            if (PackageEqualityComparer.IdAndVersion.Equals(package, conflictResult.Package))
            {
                return;
            }

            // First we get a list of dependents for the installed package.
            // Then we find the dependency in the foreach dependent that this installed package used to satisfy.
            // We then check if the resolved package also meets that dependency and if it doesn't it's added to the list
            // i.e A1 -> C >= 1
            //     B1 -> C >= 1
            //     C2 -> []
            // Given the above graph, if we upgrade from C1 to C2, we need to see if A and B can work with the new C
            var dependents = from dependentPackage in GetDependents(conflictResult)
                             where !IsDependencySatisfied(dependentPackage, package)
                             select dependentPackage;

            if (dependents.Any())
            {
                throw CreatePackageConflictException(package, conflictResult.Package, dependents);
            }
            else if (package.Version < conflictResult.Package.Version)
            {
                throw new InvalidOperationException(
                          String.Format(CultureInfo.CurrentCulture,
                                        NuGetResources.NewerVersionAlreadyReferenced, package.Id));
            }
            else if (package.Version > conflictResult.Package.Version)
            {
                // If this package isn't part of the current graph (i.e. hasn't been visited yet) and
                // is marked for removal, then do nothing. This is so we don't get unnecessary duplicates.
                if (!Marker.Contains(conflictResult.Package) &&
                    _operations.Contains(conflictResult.Package, PackageAction.Uninstall))
                {
                    return;
                }

                // Uninstall the conflicting package. We set throw on conflicts to false since we've
                // already decided that there were no conflicts based on the above code.
                var resolver = new UninstallWalker(conflictResult.Repository,
                                                   conflictResult.DependentsResolver,
                                                   NullLogger.Instance,
                                                   removeDependencies: !IgnoreDependencies,
                                                   forceRemove: false)
                {
                    ThrowOnConflicts = false
                };

                foreach (var operation in resolver.ResolveOperations(conflictResult.Package))
                {
                    _operations.AddOperation(operation);
                }
            }
        }