NuGet / Home

Repo for NuGet Client issues
Other
1.5k stars 252 forks source link

nuget list should handle protocol v3 instead of redirecting to v2 #13912

Open HaGGi13 opened 1 week ago

HaGGi13 commented 1 week ago

NuGet Product(s) Affected

NuGet.exe

Current Behavior

When it's needed to know which package versions incl. pre-release versions are available within a private package feed, the command nuget list id:<searched-package> with parameters -Source, -AllVersions and -PreRelease is run.

Meaning, for instance, following is executed to get all versions incl. pre-release versions of the package MyPackage of a private package feed listed. For simplicity the command and the result are presented as a codeblock:

PS C:\Temp> .\nuget.exe list id:MyPackage -Source https://myartifactstore/nuget/myLibraries/v3/index.json -AllVersions -PreRelease
MyPackage 1.1.2-beta.1
MyPackage 1.1.1
MyPackage 1.1.1-beta.1
MyPackage 1.1.0

As the NuGet protocol v2 is deprecated since many years, it's disabled on the private feed as well. Because of that the internal redirect of the NuGet CLI -- it's a guess that's the client and not the server does the redirect, because v2 is disabled service side -- the original output is following:

PS C:\Temp> .\nuget.exe list id:MyPackage -Source https://myartifactstore/nuget/myLibraries/v3/index.json -AllVersions -PreRelease
The V2 feed at 'https://myartifactstore/nuget/myLibraries/Search()?$orderby=Id&searchTerm='id%3AMyPackage'&targetFramework=''&includePrerelease=true&$skip=0&$top=30&semVerLevel=2.0.0' returned an unexpected status code '400 Bad Request'.

Desired Behavior

The command nuget list should be able to handle NuGet protocol v3 feeds directly instead of being depended of v2 redirects. Meaning, a source can be a v2 or a v3 feed, but the result will be the same and no error is printed.

Additional Context

It's defined that the NuGet.exe is available only, no dotnet cli, no VS PMC or similar. Because of that the set of possibilities/approaches/solutions are limited to the NuGet CLI capabilities, and additional parsing to PowerShell 5.1 capabilities.

The command nuget list output is needed to check if a specific version of a package is already available in a (private) package feed. If it's not available yet, the package must be published, even if the version to publish is older/lower than the latest stable or pre-release version.
To determine this, the result of nuget list is parsed with PowerShell (5.1).

It was considered to use nuget search instead, but it does not provide a list of all available package versions incl. pre-release versions. So the decision was made to create this behavior change request.

Instead of changing command list behavior, it would be another solution to extend the command search instead to list all available versions like list do. As far as it was possible to figure out during researches, search should already get all this information, but doesn't print it.

Any help on that is appreciated.

zivkan commented 1 week ago

If the goal is just to list the versions of a package that is available, you can achieve it with dotnet package search Some.Package --exact-match.

HaGGi13 commented 1 week ago

If the goal is just to list the versions of a package that is available, you can achieve it with dotnet package search Some.Package --exact-match.

Hi @zivkan, thanks for your reply.
Yes, I know, but as I wrote in the additional context section, no dotnet CLI or similar. Only the NuGet CLI, nothing else.