Inheritance: PackageWalker, IDependentsResolver
Example #1
0
        public virtual void AddPackageReference(IPackage package, bool ignoreDependencies, bool allowPrereleaseVersions)
        {
            // In case of a scenario like UpdateAll, the graph has already been walked once for all the packages as a bulk operation
            // But, we walk here again, just for a single package, since, we need to use UpdateWalker for project installs
            // unlike simple package installs for which InstallWalker is used
            // Also, it is noteworthy that the DependentsWalker has the same TargetFramework as the package in PackageReferenceRepository
            // unlike the UpdateWalker whose TargetFramework is the same as that of the Project
            // This makes it harder to perform a bulk operation for AddPackageReference and we have to go package by package
            var dependentsWalker = new DependentsWalker(LocalRepository, GetPackageTargetFramework(package.Id))
            {
                DependencyVersion = DependencyVersion
            };

            Execute(package, new UpdateWalker(LocalRepository,
                                              SourceRepository,
                                              dependentsWalker,
                                              ConstraintProvider,
                                              Project.TargetFramework,
                                              NullLogger.Instance,
                                              !ignoreDependencies,
                                              allowPrereleaseVersions)
            {
                DisableWalkInfo   = WhatIf,
                AcceptedTargets   = PackageTargets.Project,
                DependencyVersion = DependencyVersion
            });
        }
        public void UninstallPackage(IPackageDetails package)
        {
            Argument.IsNotNull(() => package);
            Argument.IsOfType(() => package, typeof (PackageDetails));

            var dependentsResolver = new DependentsWalker(_localRepository, null);

            var walker = new UninstallWalker(_localRepository, dependentsResolver, null,
                _logger, true, false);

            try
            {
                var nuGetPackage = ((PackageDetails) package).Package;
                var operations = walker.ResolveOperations(nuGetPackage);
                _packageManager.UninstallPackage(nuGetPackage, false, true);
            }
            catch (Exception exception)
            {
                _logger.Log(MessageLevel.Error, exception.Message);
                _packageOperationContextService.CurrentContext.CatchedExceptions.Add(exception);
            }
        }