Exemplo n.º 1
0
        public static async Task <DependencyGraphSpec> GetSolutionRestoreSpec(
            ISolutionManager solutionManager,
            DependencyGraphCacheContext context)
        {
            var dgSpec = new DependencyGraphSpec();

            var projects = (await solutionManager.GetNuGetProjectsAsync()).OfType <IDependencyGraphProject>();

            foreach (var project in projects)
            {
                var packageSpecs = await project.GetPackageSpecsAsync(context);

                foreach (var packageSpec in packageSpecs)
                {
                    dgSpec.AddProject(packageSpec);

                    if (packageSpec.RestoreMetadata.ProjectStyle == ProjectStyle.PackageReference ||
                        packageSpec.RestoreMetadata.ProjectStyle == ProjectStyle.ProjectJson ||
                        packageSpec.RestoreMetadata.ProjectStyle == ProjectStyle.DotnetCliTool ||
                        packageSpec.RestoreMetadata.ProjectStyle == ProjectStyle.Standalone)
                    {
                        dgSpec.AddRestore(packageSpec.RestoreMetadata.ProjectUniqueName);
                    }
                }
            }
            // Return dg file
            return(dgSpec);
        }
Exemplo n.º 2
0
        private async Task UpdateErrorBarAsync()
        {
            await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            try
            {
                var projects = await _solutionManager.GetNuGetProjectsAsync();

                foreach (var project in projects)
                {
                    await project.GetInstalledPackagesAsync(CancellationToken.None);
                }

                ErrorBar.Visibility = Visibility.Collapsed;
            }
            catch (Exception ex)
            {
                ErrorMessage.Text   = ex.Message;
                ErrorBar.Visibility = Visibility.Visible;
            }
            finally
            {
                InitializationCompleted?.Invoke(this, EventArgs.Empty);
            }
        }
Exemplo n.º 3
0
        public static async Task <DependencyGraphSpec> GetSolutionRestoreSpec(
            ISolutionManager solutionManager,
            DependencyGraphCacheContext context)
        {
            var dgSpec = new DependencyGraphSpec();

            var stringComparer = PathUtility.GetStringComparerBasedOnOS();

            var uniqueProjectDependencies = new HashSet <string>(stringComparer);

            var projects = ((await solutionManager.GetNuGetProjectsAsync()).OfType <IDependencyGraphProject>()).ToList();

            for (var i = 0; i < projects.Count; i++)
            {
                var packageSpecs = await projects[i].GetPackageSpecsAsync(context);

                foreach (var packageSpec in packageSpecs)
                {
                    dgSpec.AddProject(packageSpec);

                    if (packageSpec.RestoreMetadata.ProjectStyle == ProjectStyle.PackageReference ||
                        packageSpec.RestoreMetadata.ProjectStyle == ProjectStyle.ProjectJson ||
                        packageSpec.RestoreMetadata.ProjectStyle == ProjectStyle.DotnetCliTool ||
                        packageSpec.RestoreMetadata.ProjectStyle == ProjectStyle.Standalone) // Don't add global tools to restore specs for solutions
                    {
                        dgSpec.AddRestore(packageSpec.RestoreMetadata.ProjectUniqueName);

                        var projFileName = Path.GetFileName(packageSpec.RestoreMetadata.ProjectPath);
                        var dgFileName   = DependencyGraphSpec.GetDGSpecFileName(projFileName);
                        var outputPath   = packageSpec.RestoreMetadata.OutputPath;

                        if (!string.IsNullOrEmpty(outputPath))
                        {
                            var persistedDGSpecPath = Path.Combine(outputPath, dgFileName);

                            if (File.Exists(persistedDGSpecPath))
                            {
                                var persistedDGSpec = DependencyGraphSpec.Load(persistedDGSpecPath);

                                foreach (var dependentPackageSpec in persistedDGSpec.GetClosure(packageSpec.RestoreMetadata.ProjectUniqueName))
                                {
                                    if (!(uniqueProjectDependencies.Contains(dependentPackageSpec.RestoreMetadata.ProjectPath) ||
                                          projects.Any(p => stringComparer.Equals(p.MSBuildProjectPath, dependentPackageSpec.RestoreMetadata.ProjectPath))))
                                    {
                                        uniqueProjectDependencies.Add(dependentPackageSpec.RestoreMetadata.ProjectPath);
                                        dgSpec.AddProject(dependentPackageSpec);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // Return dg file
            return(dgSpec);
        }
        /// <summary>
        /// Returns all the versions of the NuGet package used in all projects in the solution
        /// ordered by latest version first.
        /// </summary>
        public static async Task <IEnumerable <NuGetVersion> > GetInstalledVersions(
            this ISolutionManager solutionManager,
            string packageId,
            CancellationToken token = default(CancellationToken))
        {
            var versions = new List <NuGetVersion> ();

            foreach (NuGetProject project in await solutionManager.GetNuGetProjectsAsync())
            {
                var packages = await project.GetInstalledPackagesAsync(token);

                versions.AddRange(packages.Where(p => IsMatch(p, packageId))
                                  .Select(p => p.PackageIdentity.Version));
            }

            return(versions.Distinct().OrderByDescending(version => version));
        }
        public async Task <IEnumerable <PackageItem> > EnumeratePackagesAsync(
            NuGetPackageManager packageManager,
            CancellationToken token)
        {
            Assumes.Present(packageManager);

            // invoke init.ps1 files in the order of package dependency.
            // if A -> B, we invoke B's init.ps1 before A's.
            var installedPackages = new List <PackageItem> ();

            var projects = (await solutionManager.GetNuGetProjectsAsync()).ToList();

            // Skip project K projects.
            projects.RemoveAll(p => p is ProjectKNuGetProjectBase);

            // Sort projects by type
            var projectLookup = projects.ToLookup(p => p is BuildIntegratedNuGetProject);

            // Each id/version should only be executed once
            var finishedPackages = new HashSet <PackageIdentity> ();

            // Packages.config projects
            await ProcessPackagesConfigProjectsAsync(
                projectLookup[false],
                packageManager,
                finishedPackages,
                installedPackages,
                token);

            // build integrated projects
            foreach (var project in projectLookup[true].Cast <BuildIntegratedNuGetProject> ())
            {
                await CollectPackagesForBuildIntegratedProjectAsync(
                    project,
                    finishedPackages,
                    installedPackages,
                    token);
            }

            return(installedPackages);
        }
        public static async Task <IEnumerable <IDotNetProject> > GetProjectsWithInstalledPackage(
            this ISolutionManager solutionManager,
            string packageId,
            string version,
            CancellationToken token = default(CancellationToken))
        {
            var nugetVersion = new NuGetVersion(version);

            var projects = new List <IDotNetProject> ();

            foreach (NuGetProject project in await solutionManager.GetNuGetProjectsAsync())
            {
                var packages = await project.GetInstalledPackagesAsync(token);

                if (packages.Any(p => IsMatch(p, packageId, nugetVersion)))
                {
                    projects.Add(project.GetDotNetProject());
                }
            }

            return(projects);
        }
        public static async Task <(DependencyGraphSpec dgSpec, IReadOnlyList <IAssetsLogMessage> additionalMessages)> GetSolutionRestoreSpecAndAdditionalMessages(
            ISolutionManager solutionManager,
            DependencyGraphCacheContext context)
        {
            var dgSpec = new DependencyGraphSpec();
            List <IAssetsLogMessage> allAdditionalMessages = null;

            var projects      = (await solutionManager.GetNuGetProjectsAsync()).OfType <IDependencyGraphProject>().ToList();
            var knownProjects = projects.Select(e => e.MSBuildProjectPath).ToHashSet(PathUtility.GetStringComparerBasedOnOS());

            for (var i = 0; i < projects.Count; i++)
            {
                var(packageSpecs, projectAdditionalMessages) = await projects[i].GetPackageSpecsAndAdditionalMessagesAsync(context);

                if (projectAdditionalMessages != null && projectAdditionalMessages.Count > 0)
                {
                    if (allAdditionalMessages == null)
                    {
                        allAdditionalMessages = new List <IAssetsLogMessage>();
                    }

                    allAdditionalMessages.AddRange(projectAdditionalMessages);
                }

                foreach (var packageSpec in packageSpecs)
                {
                    dgSpec.AddProject(packageSpec);

                    if (packageSpec.RestoreMetadata.ProjectStyle == ProjectStyle.PackageReference ||
                        packageSpec.RestoreMetadata.ProjectStyle == ProjectStyle.ProjectJson ||
                        packageSpec.RestoreMetadata.ProjectStyle == ProjectStyle.DotnetCliTool ||
                        packageSpec.RestoreMetadata.ProjectStyle == ProjectStyle.Standalone) // Don't add global tools to restore specs for solutions
                    {
                        dgSpec.AddRestore(packageSpec.RestoreMetadata.ProjectUniqueName);

                        var projFileName = Path.GetFileName(packageSpec.RestoreMetadata.ProjectPath);
                        var dgFileName   = DependencyGraphSpec.GetDGSpecFileName(projFileName);
                        var outputPath   = packageSpec.RestoreMetadata.OutputPath;

                        if (!string.IsNullOrEmpty(outputPath))
                        {
                            for (int frameworkCount = 0; frameworkCount < packageSpec.RestoreMetadata.TargetFrameworks.Count; frameworkCount++)
                            {
                                for (var projectReferenceCount = 0; projectReferenceCount < packageSpec.RestoreMetadata.TargetFrameworks[frameworkCount].ProjectReferences.Count; projectReferenceCount++)
                                {
                                    if (!knownProjects.Contains(packageSpec.RestoreMetadata.TargetFrameworks[frameworkCount].ProjectReferences[projectReferenceCount].ProjectPath))
                                    {
                                        var persistedDGSpecPath = Path.Combine(outputPath, dgFileName);
                                        if (File.Exists(persistedDGSpecPath))
                                        {
                                            var persistedDGSpec = DependencyGraphSpec.Load(persistedDGSpecPath);
                                            foreach (var dependentPackageSpec in persistedDGSpec.Projects.Where(e => !knownProjects.Contains(e.RestoreMetadata.ProjectPath)))
                                            {
                                                // Include all the missing projects from the closure.
                                                // Figuring out exactly what we need would be too and an overkill. That will happen later in the DependencyGraphSpecRequestProvider
                                                knownProjects.Add(dependentPackageSpec.RestoreMetadata.ProjectPath);
                                                dgSpec.AddProject(dependentPackageSpec);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // Return dg file
            return(dgSpec, allAdditionalMessages);
        }
        // Creates the project lists. Also called after a project is added/removed/renamed.
        private void CreateProjectLists()
        {
            // unhook event handler
            if (Projects != null)
            {
                foreach (var project in Projects)
                {
                    project.SelectedChanged -= Project_SelectedChanged;
                }
            }

            _nugetProjects = NuGetUIThreadHelper.JoinableTaskFactory.Run(async() => await _solutionManager.GetNuGetProjectsAsync());
            Projects       = _nugetProjects.Select(
                nugetProject => new PackageInstallationInfo(nugetProject))
                             .ToList();

            // hook up event handler
            foreach (var project in Projects)
            {
                project.SelectedChanged += Project_SelectedChanged;
            }

            UpdateInstalledVersions();
            UpdateSelectCheckBoxState();
            CanUninstall = false;
            CanInstall   = false;
        }