NuGet / Samples

NuGet team sample repo
Other
136 stars 108 forks source link

Add a sample for listing package ids from a feed. #41

Closed KirillOsenkov closed 3 years ago

KirillOsenkov commented 4 years ago

@loic-sharma @nkolev92

KirillOsenkov commented 4 years ago

I wasn't able to find documentation for ListResource so perhaps worth adding to the docs as well?

nkolev92 commented 4 years ago

ListResource is V2 based, it always falls back to the search/packages OData endpoint. That's really the reason why we haven't documented it and instead recommend the other 3 resources (Search, Metadata, FindPackagesById).

Those are capable of switching between implementations properly.

zivkan commented 4 years ago

I started writing this before Nikolche replied, but I was too slow because I was checking some server implementations and getting links:

This only works for v3 feeds when the service index contains a LegacyGallery link, as it's fundamentally a v2 operation.

While nuget.org, Azure DevOps, and MyGet implement it, I know that Sleet and BaGet do not. I don't know about GitHub Package Repository, or all the other servers listed in NuGet doc's hosting a package page.

A Nikolche wrote, that sample will not work for all NuGet server implementations.

KirillOsenkov commented 4 years ago

So is there a canonical way to do this properly for any feed? Or should we publish this with a disclaimer explaining that it's only for feeds that support V2, and won't work in certain servers such as Sleet and BaGet?

nkolev92 commented 4 years ago

There's no resource to list all package ids in v3 today. https://github.com/NuGet/NuGetGallery/issues/3878 is the ask afaik.

KirillOsenkov commented 4 years ago

Then let's add this sample and add a snippet in the docs clarifying the situation. It's useful in most scenarios and better than nothing.

loic-sharma commented 4 years ago

There's no resource to list all package ids in v3 today. NuGet/NuGetGallery#3878 is the ask afaik.

FYI, some V3 servers like nuget.org provide a catalog resource which can be used to discover all packages (see this tutorial). Here's a tool I wrote to do exactly just that: https://github.com/loic-sharma/nuget-mirror

For NuGet servers that do not support V2 and the catalog resource, I would recommend falling back to the search resource.

KirillOsenkov commented 4 years ago

So let's see if I'm getting this right.

  1. Some feeds support V2 only, some V3 only and some support both.
  2. All V2 feeds support ListResource as used in my sample above
  3. Some V3 feeds support catalog resource, which can also discover all packages
  4. There exist V3 feeds that don't support V2 (no ListResource) and don't provide a catalog resource

So there's no reliable way to do what I want for all feeds but some combination of ListResource and catalog resource can together provide it for most feeds.

Does this sound about right?

loic-sharma commented 4 years ago

That's right. For scenario 4, this suggestion can be used:

For NuGet servers that do not support V2 and the catalog resource, I would recommend falling back to the search resource.

In hindsight, this may be a little too complex for the SDK samples 😅

KirillOsenkov commented 4 years ago

Let's either merge this or close it, and I'm OK with either :) Thanks!