Originally published on 2015-11-21; fully revised and updated.
This guide shows how to publish a .nupkg file to NuGet.org from the command line. It is aimed at .NET developers and DevOps engineers who need a clear manual process and a simple path to automation.

What you need before publishing
- A NuGet.org account at nuget.org.
- An API key generated from your NuGet.org account settings.
- A package file ending in
.nupkg(built from your project). - Either
nuget.exeor thedotnetCLI installed on the machine that will publish.
NuGet publishing workflow
flowchart TD
A[Create NuGet account] --> B[Generate API key]
B --> C[Build and pack project]
C --> D[Prepare publish command]
D --> E[Push nupkg to nuget.org]
E --> F{Accepted by feed}
F -- yes --> G[Install by package id and version]
F -- no --> H[Fix metadata or version]
H --> C
Publish with nuget.exe (classic CLI)
The original post used nuget.exe. The same core flow still applies: store an API key, then push the package.
Step 1: Store your API key on this machine
nuget setApiKey YOUR_NUGET_API_KEY
This saves the key locally so you do not need to provide it every time on the same machine.
Step 2: Push the package
nuget push YourPackage.nupkg -Source https://api.nuget.org/v3/index.jsonCode language: JavaScript (javascript)
Publish with dotnet CLI (cross-platform)
If your build already uses the .NET SDK, you can publish with dotnet nuget push and pass the API key directly.
dotnet nuget push ./artifacts/YourPackage.1.0.0.nupkg --source https://api.nuget.org/v3/index.json --api-key YOUR_NUGET_API_KEYCode language: JavaScript (javascript)
nuget.exe vs dotnet CLI
| Option | Typical push command | Best for | Notes |
|---|---|---|---|
| nuget.exe | nuget push YourPackage.nupkg -Source https://api.nuget.org/v3/index.json | Teams already using NuGet CLI workflows | Can store API key once with nuget setApiKey. |
| dotnet CLI | dotnet nuget push ... --source https://api.nuget.org/v3/index.json --api-key ... | SDK-style .NET projects and cross-platform CI | Fits naturally into dotnet-based build pipelines. |
CI-friendly example
This example packs a project and publishes all generated packages. The API key is read from an environment variable (for example, from your CI secret store).
#!/usr/bin/env bash
set -euo pipefail
dotnet pack ./src/MyLibrary/MyLibrary.csproj -c Release -o ./artifacts
dotnet nuget push "./artifacts/*.nupkg" \
--source "https://api.nuget.org/v3/index.json" \
--api-key "$NUGET_API_KEY"Code language: PHP (php)
Verify the package after publishing
After publish completes, verify consumers can resolve the package and version from NuGet.org.
dotnet add package YourPackage --version 1.0.0Code language: CSS (css)
Reference
Original reference from the post: https://docs.nuget.org/consume/command-line-reference
Best practices
- Use a new package version for each release.
- Keep API keys in a secret manager; do not commit them to source control.
- Use the explicit NuGet.org source URL in automation for predictable behavior.
- Perform a quick install test after publish to confirm package availability.
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services — all in one place.
Explore Hospitals