Beispiel #1
0
        private IEnumerable <ResolvedAction> GetRequiredActions(PackagesContext context)
        {
            var packagesToUninstall = new HashSet <PackageIdentity>(_project.InstalledPackages.Select(x => x.Key), PackageIdentity.Comparer);
            var packagesToInstall   = new HashSet <PackageIdentity>(PackageIdentity.Comparer);

            foreach (var packageIdentity in context.Packages)
            {
                if (packagesToUninstall.Contains(packageIdentity))
                {
                    packagesToUninstall.Remove(packageIdentity);
                }
                else
                {
                    packagesToInstall.Add(packageIdentity);
                }
            }

            var actions = new List <ResolvedAction>(packagesToUninstall.Select(ResolvedAction.CreateUninstall));

            foreach (var packageIdentity in packagesToInstall)
            {
                actions.Add(ResolvedAction.CreateInstall(packageIdentity, context.PackageDependencies[packageIdentity].Source));
            }

            return(actions);
        }
Beispiel #2
0
        public async Task EnsurePackagesInstalled(PackagesLock packagesLock)
        {
            var resources = _project.PrimarySources.Concat(_project.DependencySources)
                            .ToImmutableDictionary(x => x.GetResource <FindPackageByIdResource>(), x => x);
            var cache = GetDefaultResolutionContext().SourceCacheContext;

            var actions = (await TaskCombinators.ThrottledAsync(packagesLock, async(package, token) =>
            {
                if (!_project.ModulesDirectory.ModuleExists(package.Key))
                {
                    foreach (var(resource, repo) in resources)
                    {
                        var versions =
                            await resource.GetAllVersionsAsync(package.Key.Id, cache, _logger, CancellationToken.None);
                        if (versions.Any(x => x == package.Key.Version))
                        {
                            return(ResolvedAction.CreateInstall(package.Key, repo));
                        }
                    }
                }
                return(null);
            }, CancellationToken.None)).Where(x => x != null).ToList();

            if (actions.Any())
            {
                await ExecuteActionsAsync(actions, GetDefaultDownloadContext(), CancellationToken.None);
            }
        }