Пример #1
0
        public async ValueTask <(bool, string?)> TryGetInstalledPackageFilePathAsync(
            string projectId,
            PackageIdentity packageIdentity,
            CancellationToken cancellationToken)
        {
            Assumes.NotNullOrEmpty(projectId);
            Assumes.NotNull(packageIdentity);

            cancellationToken.ThrowIfCancellationRequested();

            NuGetProject?project = await SolutionUtility.GetNuGetProjectAsync(
                _sharedState.SolutionManager,
                projectId,
                cancellationToken);

            Assumes.NotNull(project);

            string?packageFilePath = null;

            if (project is MSBuildNuGetProject msBuildProject)
            {
                packageFilePath = msBuildProject.FolderNuGetProject.GetInstalledPackageFilePath(packageIdentity);
            }

            bool success = packageFilePath != null;

            return(success, packageFilePath);
        }
Пример #2
0
        public async ValueTask <IReadOnlyCollection <PackageDependencyInfo> > GetInstalledPackagesDependencyInfoAsync(
            string projectId,
            bool includeUnresolved,
            CancellationToken cancellationToken)
        {
            Assumes.NotNullOrEmpty(projectId);

            cancellationToken.ThrowIfCancellationRequested();

            NuGetPackageManager packageManager = await _sharedState.GetPackageManagerAsync(cancellationToken);

            NuGetProject?project = await SolutionUtility.GetNuGetProjectAsync(
                _sharedState.SolutionManager,
                projectId,
                cancellationToken);

            Assumes.NotNull(project);

            IEnumerable <PackageDependencyInfo>?results = await packageManager.GetInstalledPackagesDependencyInfo(
                project,
                cancellationToken,
                includeUnresolved);

            if (results == null)
            {
                return(Array.Empty <PackageDependencyInfo>());
            }

            return(results.ToArray());
        }
Пример #3
0
        public async ValueTask <IProjectContextInfo> GetProjectAsync(string projectId, CancellationToken cancellationToken)
        {
            Assumes.NotNullOrEmpty(projectId);

            cancellationToken.ThrowIfCancellationRequested();

            NuGetProject?project = await SolutionUtility.GetNuGetProjectAsync(
                _sharedState.SolutionManager,
                projectId,
                cancellationToken);

            Assumes.NotNull(project);

            return(await ProjectContextInfo.CreateAsync(project, cancellationToken));
        }
Пример #4
0
        public async ValueTask <bool> IsProjectUpgradeableAsync(string projectId, CancellationToken cancellationToken)
        {
            Assumes.NotNullOrEmpty(projectId);

            cancellationToken.ThrowIfCancellationRequested();

            NuGetProject?project = await SolutionUtility.GetNuGetProjectAsync(
                _state.SolutionManager,
                projectId,
                cancellationToken);

            Assumes.NotNull(project);

            return(await NuGetProjectUpgradeUtility.IsNuGetProjectUpgradeableAsync(project));
        }
Пример #5
0
        private async ValueTask <MSBuildNuGetProject> GetMsBuildNuGetProjectAsync(
            string projectId,
            CancellationToken cancellationToken)
        {
            NuGetProject?project = await SolutionUtility.GetNuGetProjectAsync(
                _state.SolutionManager,
                projectId,
                cancellationToken);

            Assumes.NotNull(project);

            var msBuildProject = project as MSBuildNuGetProject;

            Assumes.NotNull(msBuildProject);

            return(msBuildProject);
        }
Пример #6
0
        public async ValueTask InstallPackagesAsync(
            string projectId,
            IReadOnlyList <PackageIdentity> packageIdentities,
            CancellationToken cancellationToken)
        {
            Assumes.NotNullOrEmpty(projectId);
            Assumes.NotNullOrEmpty(packageIdentities);

            cancellationToken.ThrowIfCancellationRequested();

            NuGetProject?project = await SolutionUtility.GetNuGetProjectAsync(
                _state.SolutionManager,
                projectId,
                cancellationToken);

            Assumes.NotNull(project);

            SourceRepository?sourceRepository = await GetSourceRepositoryAsync(cancellationToken);

            IEnumerable <NuGetProjectAction>?actions = packageIdentities
                                                       .Select(packageIdentity => NuGetProjectAction.CreateInstallProjectAction(packageIdentity, sourceRepository, project));

            NuGetPackageManager packageManager = await _state.GetPackageManagerAsync(cancellationToken);

            Assumes.NotNull(packageManager);

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

            Assumes.NotNull(projectContext);

            await packageManager.ExecuteBuildIntegratedProjectActionsAsync(
                project as BuildIntegratedNuGetProject,
                actions,
                projectContext,
                cancellationToken);
        }