public void Commit(NuGet.Common.ILogger log)
        {
            if (!Success)
            {
                var name = $"{ProjectName}.nuget.targets";
                var path = Path.Combine(ProjectDirectory, name);

                log.LogMinimal(GettextCatalog.GetString("Generating MSBuild file {0}.", name));
                GenerateMSBuildErrorFile(path);
            }
            else
            {
                // Generate the files as needed
                var targetsName = $"{ProjectName}.nuget.targets";
                var propsName   = $"{ProjectName}.nuget.props";
                var targetsPath = Path.Combine(ProjectDirectory, targetsName);
                var propsPath   = Path.Combine(ProjectDirectory, propsName);

                if (Targets.Any())
                {
                    log.LogMinimal(GettextCatalog.GetString("Generating MSBuild file {0}.", targetsName));

                    GenerateImportsFile(targetsPath, Targets);
                }
                else if (File.Exists(targetsPath))
                {
                    File.Delete(targetsPath);
                }

                if (Props.Any())
                {
                    log.LogMinimal(GettextCatalog.GetString("Generating MSBuild file {0}.", propsName));

                    GenerateImportsFile(propsPath, Props);
                }
                else if (File.Exists(propsPath))
                {
                    File.Delete(propsPath);
                }
            }
        }
        public async Task <bool> DownloadPackagesAsync(ICollection <PackageDownloadRequest> requests, TimeSpan timeout, CancellationToken cancellationToken)
        {
            logger.LogMinimal($"Downloading {requests.Count} package(s)");

            var cts = new CancellationTokenSource(timeout);

            cancellationToken.Register(() => cts.Cancel());

            using (var cacheContext = new SourceCacheContext())
                using (var throttle = new SemaphoreSlim(8))
                {
                    var defaultSettings = Settings.LoadDefaultSettings(root: null, configFileName: null, machineWideSettings: null);
                    var sourceProvider  = new CachingSourceProvider(new PackageSourceProvider(defaultSettings));
                    var tasks           = new List <Task <bool> >();

                    foreach (var request in requests)
                    {
                        var feeds = request.Sources
                                    .Select(s => s?.Trim())
                                    .Where(s => !string.IsNullOrEmpty(s))
                                    .Distinct()
                                    .Select(sourceProvider.CreateRepository);
                        tasks.Add(DownloadPackageAsync(request, feeds, cacheContext, throttle, logger, cts.Token));
                    }

                    var all   = Task.WhenAll(tasks);
                    var delay = Task.Delay(timeout);

                    var finished = await Task.WhenAny(all, delay);

                    if (ReferenceEquals(delay, finished))
                    {
                        logger.LogError($"Timed out after {timeout.TotalSeconds}s");
                        cts.Cancel();
                        return(false);
                    }

                    if (!tasks.All(a => a.Result))
                    {
                        logger.LogError("Failed to download all packages");
                        return(false);
                    }

                    return(true);
                }
        }