FuGetGallery icon indicating copy to clipboard operation
FuGetGallery copied to clipboard

Reverse assembly version search

Open afcruzs opened this issue 5 years ago • 3 comments

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?

afcruzs avatar Nov 03 '19 16:11 afcruzs

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
  }
}

loic-sharma avatar Nov 03 '19 17:11 loic-sharma

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

afcruzs avatar Nov 03 '19 21:11 afcruzs

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.

praeclarum avatar Feb 28 '21 20:02 praeclarum