コード例 #1
0
        public async ValueTask <IReadOnlyList <ProjectAction> > GetInstallActionsAsync(
            IReadOnlyCollection <string> projectIds,
            PackageIdentity packageIdentity,
            VersionConstraints versionConstraints,
            bool includePrelease,
            DependencyBehavior dependencyBehavior,
            IReadOnlyList <string> packageSourceNames,
            CancellationToken cancellationToken)
        {
            Assumes.NotNullOrEmpty(projectIds);
            Assumes.NotNull(packageIdentity);
            Assumes.NotNullOrEmpty(packageSourceNames);
            Assumes.Null(_state.PackageIdentity);
            Assumes.True(_state.ResolvedActions.Count == 0);
            Assumes.NotNull(_state.SourceCacheContext);

            cancellationToken.ThrowIfCancellationRequested();

            return(await CatchAndRethrowExceptionAsync(async() =>
            {
                _state.PackageIdentity = packageIdentity;

                IReadOnlyList <SourceRepository> sourceRepositories = GetSourceRepositories(
                    packageSourceNames,
                    cancellationToken);

                Assumes.NotNullOrEmpty(sourceRepositories);

                INuGetProjectContext projectContext = await ServiceLocator.GetComponentModelServiceAsync <INuGetProjectContext>();
                IReadOnlyList <NuGetProject> projects = await GetProjectsAsync(projectIds, cancellationToken);

                var resolutionContext = new ResolutionContext(
                    dependencyBehavior,
                    includePrelease,
                    includeUnlisted: false,
                    versionConstraints,
                    new GatherCache(),
                    _state.SourceCacheContext);

                NuGetPackageManager packageManager = await _sharedState.GetPackageManagerAsync(cancellationToken);
                IEnumerable <ResolvedAction> resolvedActions = await packageManager.PreviewProjectsInstallPackageAsync(
                    projects,
                    _state.PackageIdentity,
                    resolutionContext,
                    projectContext,
                    sourceRepositories,
                    cancellationToken);

                var projectActions = new List <ProjectAction>();

                foreach (ResolvedAction resolvedAction in resolvedActions)
                {
                    ProjectAction projectAction = CreateProjectAction(resolvedAction);

                    _state.ResolvedActions[projectAction.Id] = resolvedAction;

                    projectActions.Add(projectAction);
                }

                return projectActions;
            }));
        }
コード例 #2
0
        public async ValueTask <IReadOnlyList <ProjectAction> > GetInstallActionsAsync(
            IReadOnlyCollection <string> projectIds,
            PackageIdentity packageIdentity,
            VersionConstraints versionConstraints,
            bool includePrelease,
            DependencyBehavior dependencyBehavior,
            IReadOnlyList <string> packageSourceNames,
            CancellationToken cancellationToken)
        {
            Assumes.NotNullOrEmpty(projectIds);
            Assumes.NotNull(packageIdentity);
            Assumes.NotNullOrEmpty(packageSourceNames);
            Assumes.Null(_state.PackageIdentity);
            Assumes.True(_state.ResolvedActions.Count == 0);
            Assumes.NotNull(_state.SourceCacheContext);

            cancellationToken.ThrowIfCancellationRequested();

            _state.PackageIdentity = packageIdentity;

            IReadOnlyList <SourceRepository> sourceRepositories = await GetSourceRepositoriesAsync(
                packageSourceNames,
                cancellationToken);

            Assumes.NotNullOrEmpty(sourceRepositories);

            INuGetProjectContext projectContext = await ServiceLocator.GetInstanceAsync <INuGetProjectContext>();

            IReadOnlyList <NuGetProject> projects = await GetProjectsAsync(projectIds, cancellationToken);

            var resolutionContext = new ResolutionContext(
                dependencyBehavior,
                includePrelease,
                includeUnlisted: false,
                versionConstraints,
                new GatherCache(),
                _state.SourceCacheContext);

            NuGetPackageManager packageManager = await _sharedState.PackageManager.GetValueAsync(cancellationToken);

            IEnumerable <ResolvedAction> resolvedActions = await packageManager.PreviewProjectsInstallPackageAsync(
                projects,
                _state.PackageIdentity,
                resolutionContext,
                projectContext,
                sourceRepositories,
                cancellationToken);

            var projectActions = new List <ProjectAction>();

            foreach (ResolvedAction resolvedAction in resolvedActions)
            {
                List <ImplicitProjectAction>?implicitActions = null;

                if (resolvedAction.Action is BuildIntegratedProjectAction buildIntegratedAction)
                {
                    implicitActions = new List <ImplicitProjectAction>();

                    foreach (NuGetProjectAction?buildAction in buildIntegratedAction.GetProjectActions())
                    {
                        var implicitAction = new ImplicitProjectAction(
                            CreateProjectActionId(),
                            buildAction.PackageIdentity,
                            buildAction.NuGetProjectActionType);

                        implicitActions.Add(implicitAction);
                    }
                }

                string projectId     = resolvedAction.Project.GetMetadata <string>(NuGetProjectMetadataKeys.ProjectId);
                var    projectAction = new ProjectAction(
                    CreateProjectActionId(),
                    projectId,
                    resolvedAction.Action.PackageIdentity,
                    resolvedAction.Action.NuGetProjectActionType,
                    implicitActions);

                _state.ResolvedActions[projectAction.Id] = resolvedAction;

                projectActions.Add(projectAction);
            }

            return(projectActions);
        }