Last active
January 22, 2020 18:13
-
-
Save loic-sharma/107210ba996fba598b6fdb5143ed847b to your computer and use it in GitHub Desktop.
Get the download count for all versions of a package
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <Project Sdk="Microsoft.NET.Sdk"> | |
| <PropertyGroup> | |
| <OutputType>Exe</OutputType> | |
| <TargetFramework>netcoreapp3.1</TargetFramework> | |
| </PropertyGroup> | |
| <ItemGroup> | |
| <PackageReference Include="NuGet.Protocol" Version="5.5.0-preview.1.6319" /> | |
| </ItemGroup> | |
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Linq; | |
| using System.Threading; | |
| using System.Threading.Tasks; | |
| using NuGet.Common; | |
| using NuGet.Configuration; | |
| using NuGet.Protocol.Core.Types; | |
| namespace ConsoleApp17 | |
| { | |
| public class Program | |
| { | |
| public static async Task Main(string[] args) | |
| { | |
| var source = new PackageSource("https://api.nuget.org/v3/index.json"); | |
| var providers = Repository.Provider.GetCoreV3(); | |
| var repository = new SourceRepository(source, providers); | |
| var searchResource = await repository.GetResourceAsync<PackageSearchResource>(); | |
| var searchFilter = new SearchFilter(includePrerelease: true); | |
| var results = await searchResource.SearchAsync("packageId:Newtonsoft.Json", searchFilter, skip: 0, take: 1, NullLogger.Instance, CancellationToken.None); | |
| if (results.Count() != 1) | |
| { | |
| throw new InvalidOperationException($"Expected 1 result, found {results.Count()}"); | |
| } | |
| var package = results.First(); | |
| Console.WriteLine($"Package {package.Identity.Id} has {package.DownloadCount} total downloads across all versions"); | |
| foreach (var version in await package.GetVersionsAsync()) | |
| { | |
| Console.WriteLine($"Found version {version.Version.ToNormalizedString()} with {version.DownloadCount} downloads"); | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Package Newtonsoft.Json has 363187770 total downloads across all versions | |
| Found version 3.5.8 with 360077109 downloads | |
| Found version 4.0.1 with 360077109 downloads | |
| Found version 4.0.2 with 360077109 downloads | |
| Found version 4.0.3 with 360077109 downloads | |
| Found version 4.0.4 with 360077109 downloads | |
| Found version 4.0.5 with 360077109 downloads | |
| Found version 4.0.6 with 360077109 downloads | |
| Found version 4.0.7 with 360077109 downloads | |
| Found version 4.0.8 with 360077109 downloads | |
| Found version 4.5.1 with 360077109 downloads | |
| Found version 4.5.2 with 360077109 downloads | |
| Found version 4.5.3 with 360077109 downloads | |
| Found version 4.5.4 with 360077109 downloads | |
| Found version 4.5.5 with 360077109 downloads | |
| Found version 4.5.6 with 360077109 downloads | |
| Found version 4.5.7 with 360077109 downloads | |
| Found version 4.5.8 with 360077109 downloads | |
| Found version 4.5.9 with 360077109 downloads | |
| Found version 4.5.10 with 360077109 downloads | |
| Found version 4.5.11 with 360077109 downloads | |
| Found version 5.0.1 with 360077109 downloads | |
| Found version 5.0.2 with 360077109 downloads | |
| Found version 5.0.3 with 360077109 downloads | |
| Found version 5.0.4 with 360077109 downloads | |
| Found version 5.0.5 with 360077109 downloads | |
| Found version 5.0.6 with 360077109 downloads | |
| Found version 5.0.7 with 360077109 downloads | |
| Found version 5.0.8 with 360077109 downloads | |
| Found version 6.0.1 with 360077109 downloads | |
| Found version 6.0.2 with 360077109 downloads | |
| Found version 6.0.3 with 360077109 downloads | |
| Found version 6.0.4 with 360077109 downloads | |
| Found version 6.0.5 with 360077109 downloads | |
| Found version 6.0.6 with 360077109 downloads | |
| Found version 6.0.7 with 360077109 downloads | |
| Found version 6.0.8 with 360077109 downloads | |
| Found version 7.0.1 with 360077109 downloads | |
| Found version 8.0.1 with 360077109 downloads | |
| Found version 8.0.2 with 360077109 downloads | |
| Found version 8.0.3 with 360077109 downloads | |
| Found version 9.0.1 with 360077109 downloads | |
| Found version 10.0.1 with 360077109 downloads | |
| Found version 10.0.2 with 360077109 downloads | |
| Found version 10.0.3 with 360077109 downloads | |
| Found version 11.0.1 with 360077109 downloads | |
| Found version 11.0.2 with 360077109 downloads | |
| Found version 12.0.1 with 360077109 downloads | |
| Found version 12.0.2 with 360077109 downloads | |
| Found version 12.0.3 with 360077109 downloads |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment