MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

Publish NuGet Packages to NuGet.org: CLI Steps, Workflow, and CI Example

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.

publish-a-nuget-package-in-nuget-gallery

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.exe or the dotnet CLI 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

OptionTypical push commandBest forNotes
nuget.exenuget push YourPackage.nupkg -Source https://api.nuget.org/v3/index.jsonTeams already using NuGet CLI workflowsCan store API key once with nuget setApiKey.
dotnet CLIdotnet nuget push ... --source https://api.nuget.org/v3/index.json --api-key ...SDK-style .NET projects and cross-platform CIFits 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.

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
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.

Related Posts

Host Your Own NuGet Feed: Local Source vs NuGet.Server vs NuGetGallery

Learn how to host a private NuGet feed using three practical approaches: a local folder source, NuGet.Server, and NuGetGallery. This revised guide includes setup steps, command examples, and a workflow diagram to help you choose the right model.

Read More

How to Create NuGet Packages with nuget.exe (Assembly, .nuspec, and .csproj Methods)

Learn three practical ways to build NuGet packages using nuget.exe: from an existing assembly, from a convention-based folder layout, or directly from a Visual Studio project. This guide includes commands, folder conventions, token behavior, and common pitfalls.

Read More

Team Foundation Build 2010: Architecture, Build Definitions, and Migration from TFS 2008

Team Foundation Build 2010 introduced a controller/agent build architecture, richer build definitions, and gated check-in workflows for TFS teams. This revised guide turns the original topic list into a practical reference for setup, customization, and migration planning.

Read More

.NET Build and Release Training: Curriculum, Toolchain, Workflow, and Enrollment

A structured, engineer-friendly rewrite of the original .NET Build and Release course page. Review objectives, tool coverage, CI/CD workflow, prerequisites, fees, and key links in one place.

Read More

NAnt Training Guide for Build and Release Engineers: Syllabus, Labs, and Workflow

A revised NAnt training page focused on practical skills for SCM, build, and release engineers. It includes the original syllabus topics, delivery options, a CI workflow diagram, and hands-on NAnt examples.

Read More

MSBuild Training Guide: Basics, Custom Targets, Logging, and Troubleshooting

A practical, updated MSBuild training reference based on the original course outline. Learn how MSBuild works, how to customize builds, and how to troubleshoot slow or failing pipelines.

Read More
Subscribe
Notify of
guest
1 Comment
Newest
Oldest Most Voted
Puja kushwaha
Puja kushwaha
27 days ago

Publishing a NuGet package requires more than uploading the file; clear versioning and package details matter too. Before publishing, test the package in a separate project to confirm it installs and works as expected. Keep the README, dependencies, and license information accurate so other developers can use it with confidence. Protect your API key and avoid storing it in source control. These checks help make packages safer to share and easier to maintain.

1
0
Would love your thoughts, please comment.x
()
x