This document describes how to publish a new version of Lifx.Api to NuGet.org.
-
PowerShell 7.0+
# Check version pwsh --version -
.NET 10.0 SDK
dotnet --version
-
Nerdbank.GitVersioning CLI
dotnet tool install -g nbgv
-
NuGet API Key
- Get your key from https://www.nuget.org/account/apikeys
- Create
nuget-key.txtin the repository root - Add your API key to this file (it's .gitignored)
Simply run the publish script:
.\Publish.ps1The script will:
- Check for clean git working directory (porcelain)
- Verify all prerequisites are installed
- Run all tests (must pass 100%)
- Get version from Nerdbank.GitVersioning
- Build the NuGet package
- Create git tag (e.g.,
v1.0.0) - Publish to NuGet.org
- Push git tag to remote
If you need to publish manually:
-
Ensure clean git state
git status # Should show "nothing to commit, working tree clean" -
Run all tests
dotnet test --configuration Release -
Get version
nbgv get-version
-
Build package
dotnet pack ./Lifx.Api/Lifx.Api.csproj --configuration Release --output ./nupkgs
-
Create git tag
git tag -a v1.0.0 -m "Release 1.0.0" -
Publish to NuGet
dotnet nuget push ./nupkgs/Lifx.Api.1.0.0.nupkg --api-key YOUR_KEY --source https://api.nuget.org/v3/index.json
-
Push tag to remote
git push origin v1.0.0
This project uses Nerdbank.GitVersioning for automatic semantic versioning based on git history.
Version is controlled by version.json in the repository root:
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "1.0",
"publicReleaseRefSpec": [
"^refs/heads/main$",
"^refs/heads/master$"
]
}To increment the version:
-
Patch version (1.0.0 -> 1.0.1)
- Automatic on each commit
-
Minor version (1.0.x -> 1.1.0)
nbgv set-version 1.1 git add version.json git commit -m "Increment minor version to 1.1" -
Major version (1.x.x -> 2.0.0)
nbgv set-version 2.0 git add version.json git commit -m "Increment major version to 2.0"
- Releases from main/master:
1.0.0 - Pre-releases:
1.0.0-alpha.{height}(based on commit height) - Local builds:
1.0.0-{branchName}.{height}
- Commit or stash all changes before publishing
- Check with
git status
- Fix failing tests before publishing
- Run tests locally:
dotnet test - Check test output for specific failures
- Version needs to be incremented
- Either increment manually or make a new commit (auto-increments patch)
- Create the file in repository root
- Add your NuGet API key
- Verify file is .gitignored
- Check API key is valid and not expired
- Verify package doesn't already exist with this version
- Check NuGet.org status: https://status.nuget.org/
- Check you have push permissions to the repository
- Manually push:
git push origin v1.0.0
- Never commit
nuget-key.txt- It's .gitignored for security - Keep your NuGet API key private
- Rotate keys periodically
- Use scoped keys (push-only for specific packages)
After successful publish:
-
Package appears on NuGet.org (may take a few minutes)
-
Update release notes on GitHub
-
Announce release (optional)
- Update documentation
- Social media
- Blog posts
For automated publishing via GitHub Actions or Azure DevOps:
- Store NuGet API key as a secret
- Run
Publish.ps1in CI pipeline - Only publish from main/master branch
- Ensure all tests pass before publish
Example GitHub Actions workflow:
name: Publish to NuGet
on:
push:
branches: [ main ]
tags: [ 'v*' ]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '10.0.x'
- name: Install nbgv
run: dotnet tool install -g nbgv
- name: Create nuget-key.txt
run: echo "${{ secrets.NUGET_API_KEY }}" > nuget-key.txt
- name: Publish
run: pwsh ./Publish.ps1For issues with publishing:
- Check this guide
- Review script output for errors
- Open an issue: https://github.com/panoramicdata/Lifx.Api/issues