예제 #1
0
        public async Task <IEnumerable <PackageAction> > ResolveActionsAsync(IExecutionLogger logger)
        {
            var model  = (DetailControlModel)DataContext;
            var action = model.SelectedAction == Resx.Resources.Action_Uninstall ?
                         PackageActionType.Uninstall :
                         PackageActionType.Install;

            // Create resolver
            var repo = Control.CreateActiveRepository();

            if (action == PackageActionType.Uninstall)
            {
                // for uninstall, use local repo
                repo = Control.Target.TryGetFeature <SourceRepository>();
            }
            if (repo == null)
            {
                throw new InvalidOperationException(Resx.Resources.Error_NoActiveRepository);
            }

            var dependencyResolutionRepo = Control.CreateAggregateSourceRepository();
            var resolver = new ActionResolver(
                repo,
                dependencyResolutionRepo,
                new ResolutionContext()
            {
                DependencyBehavior = model.Options.SelectedDependencyBehavior.Behavior,
                AllowPrerelease    = Control.IncludePrerelease,
                ForceRemove        = model.Options.ForceRemove,
                RemoveDependencies = model.Options.RemoveDependencies
            });

            resolver.Logger = logger;

            IEnumerable <Project> targetProjects;
            var solutionModel = DataContext as PackageSolutionDetailControlModel;

            if (solutionModel != null)
            {
                targetProjects = solutionModel.Projects
                                 .Where(p => p.Selected)
                                 .Select(p => p.Project);
            }
            else
            {
                var project = Control.Target as Project;
                targetProjects = new[] { project };
                Debug.Assert(project != null);
            }

            return(await resolver.ResolveActionsAsync(
                       new PackageIdentity(model.Id, model.SelectedVersion.Version),
                       action,
                       targetProjects,
                       Control.Target.OwnerSolution));
        }
        private async Task InstallPackage(
            IFileSystem installPathFileSystem,
            string packageId,
            NuGetVersion version)
        {
            if (version == null)
            {
                NoCache = true;
            }
            var packageManager = CreatePackageManager(installPathFileSystem, useSideBySidePaths: true);

            // BUGBUG: When adding support for 'AllowMultipleVersions', remember to add PackageInstallNeeded method

            JObject packageMetadata;

            if (version == null)
            {
                packageMetadata = await SourceRepositoryHelper.GetLatestVersionMetadata(SourceRepository, packageId, prerelease : Prerelease);

                version = NuGetVersion.Parse(packageMetadata["version"].ToString());
            }
            else
            {
                packageMetadata = await SourceRepository.GetPackageMetadata(packageId, version);
            }

            if (packageMetadata == null)
            {
                throw new InvalidOperationException(
                          String.Format(CultureInfo.CurrentCulture,
                                        NuGet.Resources.NuGetResources.UnknownPackageSpecificVersion, packageId, version));
            }

            var actionResolver = new ActionResolver(
                SourceRepository,
                SourceRepository,
                new ResolutionContext()
            {
                AllowPrerelease    = Prerelease,
                DependencyBehavior = DependencyBehavior,
            });

            var packageActions = await actionResolver.ResolveActionsAsync(new PackageIdentity(packageId, version),
                                                                          PackageActionType.Install,
                                                                          new FilesystemInstallationTarget(packageManager));

            if (Verbosity == NuGet.Verbosity.Detailed)
            {
                Console.WriteLine("Actions returned by resolver");
                foreach (var action in packageActions)
                {
                    Console.WriteLine(action.ActionType.ToString() + "-" + action.PackageIdentity.ToString());
                }
            }

            packageActions = packageActions.Where(a => a.ActionType == PackageActionType.Download || a.ActionType == PackageActionType.Purge);

            if (Verbosity == NuGet.Verbosity.Detailed)
            {
                Console.WriteLine("After reducing actions to just Download and Purge");
                foreach (var action in packageActions)
                {
                    Console.WriteLine(action.ActionType.ToString() + "-" + action.PackageIdentity.ToString());
                }
            }

            var actionExecutor = new ActionExecutor();

            actionExecutor.ExecuteActions(packageActions, Console);
        }