praeclarum / FuGetGallery

An alternative web UI for browsing nuget packages
https://www.fuget.org
MIT License
685 stars 121 forks source link

Reverse assembly version search #87

Open afcruzs opened 5 years ago

afcruzs commented 5 years ago

I've been on situations where given a package name and an assembly version I need to figure out the nuget version. Do you think it would be appropriate to add that feature to fuget or is it out of scope?

loic-sharma commented 5 years ago

This is a tricky problem by itself as many NuGet packages may have that exact assembly. Personally I would recommend building a custom tool that uses the NuGet package content API to discover the versions for a package. Then, I would download each package and check each assembly individually. You should be able to do this using the NuGet client libraries or my BaGet.Protocol package:

NuGetClient client = new NuGetClient("https://api.nuget.org/v3/index.json");

IReadOnlyList<NuGetVersion>> versions = await client.ListPackageVersionsAsync("Newtonsoft.Json");

foreach (NuGetVersion version in versions)
{
  using (Stream packageStream = await client.GetPackageStreamAsync(packageId, packageVersion))
  {
    // You'll want to copy the packageStream to a seekable stream
    // You'll want to use the "PackageArchiveReader" type from "NuGet.Packaging" to inspect the package stream and extract DLLs
  }
}
afcruzs commented 5 years ago

Yep, that was my first thought. Thanks Ioic I'll take a look to BaGet.

praeclarum commented 3 years ago

I am considering indexing APIs however which would include the assembly name so it's not out of the question. Even if there are collisions it still might be a useful query to have.