Example #1
0
        private async Task <bool> CheckCanBeInstalledAsync(IExtensibleProject project, PackageReaderBase packageReader, NuGetFramework targetFramework, CancellationToken token)
        {
            Argument.IsNotNull(() => project);
            Argument.IsNotNull(() => packageReader);

            var frameworkReducer = new FrameworkReducer();

            var libraries = await packageReader.GetLibItemsAsync(token);

            var libraryTfms = libraries.Select(x => x.TargetFramework).ToList();

            var bestMatches = frameworkReducer.GetNearest(targetFramework, libraryTfms);

            if (bestMatches is null)
            {
                // Try to find first supported platform-specific version
                foreach (var platformSpecific in project.SupportedPlatforms)
                {
                    bestMatches = frameworkReducer.GetNearest(platformSpecific, libraryTfms);

                    if (bestMatches is not null)
                    {
                        break;
                    }
                }
            }

            return(bestMatches is not null);
        }
        public async Task <IReadOnlyCollection <MetadataReference> > Install(string packageSearchTerm, IReplLogger logger)
        {
            var nugetLogger = new NugetErrorLogger(logger);

            logger.LogOutput($"Searching for {packageSearchTerm}");
            var package = await FindPackageAsync(packageSearchTerm, repositories, nugetLogger);

            if (package == null)
            {
                logger.LogError($"Could not find package '{packageSearchTerm}'");
                return(Array.Empty <MetadataReference>());
            }
            logger.LogOutput("Found " + Display(package));
            logger.LogOutput("Determining dependences...");

            var dependencies = await GetPackageDependencies(package, nugetFramework, nugetCache, nugetLogger, repositories);

            var packagesToInstall        = ResolvePackages(package, dependencies, nugetLogger);
            var packageExtractionContext = new PackageExtractionContext(
                PackageSaveMode.Defaultv3,
                XmlDocFileSaveMode.None,
                clientPolicy,
                nugetLogger);

            var assemblyPaths = await Task.WhenAll(packagesToInstall
                                                   .Select(async packageToInstall =>
            {
                var installedPath = packagePathResolver.GetInstalledPath(packageToInstall);
                PackageReaderBase packageReader = installedPath == null
                        ? await DownloadPackage(packageToInstall, packageExtractionContext, nugetLogger)
                        : LocalPackageReader(packageToInstall, installedPath, nugetLogger);

                var allResources = await Task.WhenAll(
                    packageReader.GetLibItemsAsync(CancellationToken.None),
                    packageReader.GetFrameworkItemsAsync(CancellationToken.None)
                    );

                installedPath ??= packagePathResolver.GetInstalledPath(packageToInstall);
                var references = DotNetAssemblyLocator.GroupDirectoryContentsIntoAssemblies(
                    FilterByFramework(frameworkReducer, allResources.SelectMany(x => x).ToList())
                    .Select(item => Path.Combine(installedPath, item))
                    )
                                 .Select(assembly => io.CreateMetadataReferenceWithDocumentation(assembly))
                                 .ToList();

                logger.LogOutput("Installation complete for " + Display(packageToInstall));

                return(references);
            })
                                                   );

            return(assemblyPaths
                   .SelectMany(assemblyGroup => assemblyGroup)
                   .ToList());
        }
Example #3
0
        private async Task <(string frameworkFolderName, IEnumerable <string> packagePaths)> EnumerateFiles(CancellationToken cancellationToken)
        {
            foreach (FrameworkSpecificGroup group in await reader.GetLibItemsAsync(cancellationToken))
            {
                if (filter.IsPassed(group))
                {
                    return(group.TargetFramework.GetShortFolderName(), group.Items);
                }
            }

            return(null, Enumerable.Empty <string>());
        }