nuget.exe: restore and push Packages in CI
nuget.exe restore pulls dependencies for a solution and nuget.exe push uploads a .nupkg to a feed; in CI you supply the feed with -Source and the credential with -ApiKey.
The standalone nuget.exe is still needed for classic packages.config / .NET Framework restores and for pushing packages, even where dotnet handles SDK-style projects.
What it does
nuget.exe restore reads a solution or packages.config and downloads the referenced packages. nuget.exe push uploads a built .nupkg (and its .snupkg symbols) to a NuGet v2/v3 feed authenticated by an API key.
Common usage
:: restore for a classic solution
nuget restore MyApp.sln -NonInteractive
:: push a package, ignoring a re-pushed version
nuget push bin\Release\MyPkg.1.2.3.nupkg ^
-ApiKey %NUGET_API_KEY% ^
-Source https://api.nuget.org/v3/index.json ^
-SkipDuplicateOptions
| Command / flag | What it does |
|---|---|
| restore <sln> | Restore packages for a solution |
| push <nupkg> | Upload a package to a feed |
| -Source <url> | Feed URL or named source |
| -ApiKey <key> | Credential for the push |
| -SkipDuplicate | Return success if the version already exists |
| -NonInteractive | Never prompt (required in CI) |
In CI
Add -SkipDuplicate so a re-run that re-pushes an already-published version does not fail the job with a 409. Always pass -NonInteractive and supply the API key from a secret. For SDK-style projects, dotnet restore/dotnet nuget push is the modern equivalent.
Common errors in CI
"Response status code does not indicate success: 401 (Unauthorized)" means a missing or wrong -ApiKey, or the key lacks push scope. "409 (Conflict): A package with ID ... and version ... already exists" means you re-pushed an existing version; add -SkipDuplicate. "Unable to load the service index for source" means the feed URL is wrong or unreachable. "Unable to find version ... of package" on restore points at a feed that does not have the pinned version.