Reputation: 9089
Using .NET Core/Standard (C#) I'd like to retrieve details of all the nuget packages for a particular owner.
For example supplying "charliepoole" would give me all the related packages like on the page: https://www.nuget.org/profiles/charliepoole
I'm currently using package NuGet.ProjectModel
to retrieve individual packages by ID/Version but there does not seem to be any other related methods that can help me.
For reference this is how I'm retrieving an individual package by ID and version:
public async Task<IPackageSearchMetadata> GetPackageAsync(string id, string version, CancellationToken cancellationToken = default)
{
var packageSource = new PackageSource("https://api.nuget.org/v3/index.json", "NugetV3");
var providers = new List<Lazy<INuGetResourceProvider>>();
providers.AddRange(Repository.Provider.GetCoreV3());
var repo = new SourceRepository(packageSource, providers);
var packageMetadataResource = await repo.GetResourceAsync<PackageMetadataResource>(cancellationToken);
var packageIdentity = new PackageIdentity(id, NuGetVersion.Parse(version));
var context = new SourceCacheContext
{
NoCache = true,
DirectDownload = true
};
return await packageMetadataResource
.GetMetadataAsync(packageIdentity, context, new NullLogger(), cancellationToken);
}
Is this possible using any of the official supplied nuget packages that talk to the nuget API?
Upvotes: 2
Views: 1538
Reputation: 14981
Is this possible using any of the official supplied nuget packages that talk to the nuget API?
Not really, no.
The NuGet client team calls the packages they publish on nuget.org the NuGet (Client) SDK. NuGet.Protocol is the package that implements the client side of NuGet's server HTTP API. The NuGet SDK doesn't implement all of the server API, just the parts used in Visual Studio.
Since your question is about searching, the search docs are relevant. Looking at the response schema, we can see that owners
is one of the fields, but looking at the request parameters, there's no query to ask specifically about an owner.
So, you can try passing the nuget.org account name you're interested as a search keyword and hope that the search index has that information. When you get results back, you can check each package and ignore the ones that don't have the account you're looking for as a package owner.
Two other server API resources that have package metadata are the catalog (transaction log of all packages processed by the ingestion pipeline), and package metadata, but neither show owner information.
However, the NuGet server team's issue tracker is GitHub's NuGet/NuGetGallary repo, and I found an issue asking how to get the list of owners of a given package on nuget.org. They acknowledged it's a shortcoming of the protocol. You can upvote that issue to signal that it's important (there's only 1 upvote so far, so it seems this is not important to most customers). But they also replied with an unofficial, undocumented URL that contains the owner list for all packages. You can use this, but obviously consider the risk that it could theoretically change at any time. Having said that, the comment was posted 2 years ago and it still works.
Upvotes: 2