Created
February 13, 2018 19:06
-
-
Save joelverhagen/4d32044a8003360e81c68ac82ac318cc to your computer and use it in GitHub Desktop.
NuGet API, get download count per version
This file contains 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
// All you need is the NuGet.Protocol package from NuGet.org. | |
using System; | |
using System.Threading; | |
using System.Threading.Tasks; | |
using NuGet.Common; | |
using NuGet.Protocol; | |
using NuGet.Protocol.Core.Types; | |
namespace ConsoleApp1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
MainAsync().GetAwaiter().GetResult(); | |
} | |
static async Task MainAsync() | |
{ | |
var sourceRepository = Repository.Factory.GetCoreV3("https://api.nuget.org/v3/index.json"); | |
var search = await sourceRepository.GetResourceAsync<RawSearchResourceV3>(); | |
var results = await search.Search( | |
"packageid:Newtonsoft.Json", | |
new SearchFilter(includePrerelease: true), | |
skip: 0, | |
take: 1, | |
log: NullLogger.Instance, | |
cancellationToken: CancellationToken.None); | |
foreach (var result in results) | |
{ | |
foreach (var version in result["versions"]) | |
{ | |
Console.WriteLine($"{version["version"]} {version["downloads"]}"); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment