Exemple #1
0
        PackagePhysicalFileMetadata DownloadPackage(
            string packageId,
            IVersion version,
            Uri feedUri,
            ICredentials feedCredentials,
            string cacheDirectory,
            int maxDownloadAttempts,
            TimeSpan downloadAttemptBackoff)
        {
            Log.Info("Downloading NuGet package {0} v{1} from feed: '{2}'", packageId, version, feedUri);
            Log.VerboseFormat("Downloaded package will be stored in: '{0}'", cacheDirectory);
            freeSpaceChecker.EnsureDiskHasEnoughFreeSpace(cacheDirectory);

            var fullPathToDownloadTo = Path.Combine(cacheDirectory, PackageName.ToCachedFileName(packageId, version, ".nupkg"));

            var downloader = new InternalNuGetPackageDownloader(fileSystem);

            downloader.DownloadPackage(packageId,
                                       version,
                                       feedUri,
                                       feedCredentials,
                                       fullPathToDownloadTo,
                                       maxDownloadAttempts,
                                       downloadAttemptBackoff);

            var pkg = PackagePhysicalFileMetadata.Build(fullPathToDownloadTo);

            if (pkg == null)
            {
                throw new CommandException($"Package metadata for {packageId}, version {version}, could not be determined");
            }

            CheckWhetherThePackageHasDependencies(pkg);
            return(pkg);
        }
Exemple #2
0
        PackagePhysicalFileMetadata?AttemptToGetPackageFromCache(string packageId, IVersion version, string cacheDirectory)
        {
            Log.VerboseFormat("Checking package cache for package {0} v{1}", packageId, version.ToString());

            var files = fileSystem.EnumerateFilesRecursively(cacheDirectory, PackageName.ToSearchPatterns(packageId, version, new[] { ".nupkg" }));

            foreach (var file in files)
            {
                var package = PackageName.FromFile(file);
                if (package == null)
                {
                    continue;
                }

                var idMatches         = string.Equals(package.PackageId, packageId, StringComparison.OrdinalIgnoreCase);
                var versionExactMatch = string.Equals(package.Version.ToString(), version.ToString(), StringComparison.OrdinalIgnoreCase);
                var nugetVerMatches   = package.Version.Equals(version);

                if (idMatches && (nugetVerMatches || versionExactMatch))
                {
                    return(PackagePhysicalFileMetadata.Build(file, package));
                }
            }

            return(null);
        }