Repository navigation
Description
Summary
When pushing a package fails, Nuget.exe should return a different exitcode for different status codes.
Problem description
When pushing a package to a nuget feed fails, Nuget.Exe prints out the error and returns '1' as the exitcode, to indicate that it fails, regardless of the reason of the failure.
This is especially problematic when pushing a package with the same version twice (but with different build metadata). The server returns a 409 status code, but Nuget.Exe only returns the exitcode 1, indicating a failure. Because Nuget.Exe only returns '1', it becomes very difficult to programmatically control what it should do, for example from a script.
Http statuscodes carry meaning about the actual reason for failure. Having to grep this from stdout is not really a solid solution, so it would be much better.
Some more background
We build and push packages to nuget / myget as part of our CI pipeline. Sometimes it's needed to re-run a build (for whatever reason). Now, rerunning a succesful build will fail the second time, because a package with the same build metadata cannot be pushed again.
Suggested solution
If the nuget push fails, Nuget.exe should return the statuscode as exit code. Any non zero exit code indicates failure, but the invoker of nuget can derive meaning from the httpstatuscode as well.
Implementation option 1:
The following line currently rethrows the http exception:
https://github.com/NuGet/NuGet.Client/blob/dev/src/NuGet.Core/NuGet.Protocol/Resources/PackageUpdateResource.cs#L327
If pushing a package fails, we could throw a new ExitCodeException(response.statuscode).
Implementation option 2:
We can also catch the HttpRequestException and throw an ExitCodeException(response.statuscode) in the Nuget.Client PushCommand:
Implementation option 3:
We can catch the HttpRequestException at the top level and return the statuscode as an exit code.
Related
The issue #1630 tries to resolve the same problem, but with a different approach.
Activity
adamralph commentedon Feb 27, 2019
FWIW, I believe #1630 is a better solution.
dotnet-policy-service commentedon May 7, 2026
Due to lack of recent activity, this issue has been marked as a candidate for icebox cleanup. It will be closed if no further activity occurs within 14 more days. If the issue receives enough upvotes, it will be flagged with
Triage:NeedsTriageDiscussionfor team review.This process is part of the experimental Stale icebox issues cleanup we are currently trialing. Please share any feedback you might have in the linked issue.
dotnet-policy-service commentedon May 21, 2026
This issue will now be closed since it had been marked Icebox cleanup candidate, but received no further activity in the past 14 days.
adamralph commentedon Jul 29, 2026
Should be closed as not planned.