public async Task <LocalPackageSourceInfo> EnsureLocalPackage(IRemoteDependencyProvider provider, PackageIdentity packageIdentity) { if (!_v3LocalRepository.Exists(packageIdentity.Id, packageIdentity.Version)) { var packageDependency = await provider.GetPackageDownloaderAsync(packageIdentity, _cache, _context.Logger, CancellationToken.None); var installed = await PackageExtractor.InstallFromSourceAsync( packageIdentity, packageDependency, _v3LocalRepository.PathResolver, _context, CancellationToken.None, Guid.NewGuid()); // 1) If another project in this process installs the package this will return false but userPackageFolder will contain the package. // 2) If another process installs the package then this will also return false but we still need to update the cache. // For #2 double check that the cache has the package now otherwise clear if (installed || !_v3LocalRepository.Exists(packageIdentity.Id, packageIdentity.Version)) { // If the package was added, clear the cache so that the next caller can see it. // Avoid calling this for packages that were not actually installed. _v3LocalRepository.ClearCacheForIds(new string[] { packageIdentity.Id }); } } return(NuGetv3LocalRepositoryUtility.GetPackage(new[] { _v3LocalRepository }, packageIdentity.Id, packageIdentity.Version)); }
/// <summary> /// Find all package versions from a source. /// </summary> internal static async Task <KeyValuePair <PackageSource, SortedSet <NuGetVersion> > > GetSourceInfoForIdAsync( IRemoteDependencyProvider provider, string id, SourceCacheContext cacheContext, ILogger logger, CancellationToken token) { // Find all versions from a source. var versions = await provider.GetAllVersionsAsync(id, cacheContext, logger, token) ?? Enumerable.Empty <NuGetVersion>(); return(new KeyValuePair <PackageSource, SortedSet <NuGetVersion> >( provider.Source, new SortedSet <NuGetVersion>(versions))); }
static async Task <RemoteMatch> FindLibraryFromProviderAsync(IRemoteDependencyProvider provider, LibraryRange libraryRange, NuGetFramework framework, SourceCacheContext cacheContext, ILogger logger, CancellationToken token) { var library = await provider.FindLibraryAsync(libraryRange, framework, cacheContext, logger, token); if (library != null) { return(new RemoteMatch { Provider = provider, Library = library }); } return(null); }