Nuget Trusted Publishing
.NET (Microsoft)OfficialPublished by .NET (Microsoft)
- Skill
- Tool integration
- Software development
- MIT
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill guides you through migrating from long-lived NuGet API keys to OIDC-based trusted publishing. By leveraging GitHub Actions' native identity tokens, you can publish NuGet packages securely without managing or rotating sensitive secrets. The process includes assessing your project structure, configuring the required nuget.org policy, and updating your GitHub Actions workflow to use the NuGet login action.
What it does
- Assesses .csproj files to identify packable projects and verify metadata requirements.
- Provides guidance for creating trusted publishing policies on nuget.org.
- Generates or updates GitHub Actions workflows to support OIDC-based authentication.
- Replaces static API key secrets with secure, short-lived OIDC tokens.
- Validates package structure and versioning consistency before publishing.
- Offers troubleshooting steps for common OIDC and workflow configuration issues.
When to use it
- When you want to eliminate the risk of leaking long-lived NuGet API keys.
- When migrating an existing project from API key-based publishing to OIDC.
- When setting up a new NuGet package, dotnet tool, or MCP server workflow.
- When you need to configure secure, automated publishing for a GitHub repository.
Advantages
- Eliminates the need to store and rotate sensitive NuGet API keys.
- Reduces security risks associated with credential exposure.
- Automates the authentication process using native GitHub Actions identity tokens.
- Provides a clear, phased approach to migration and setup.
Usage examples
- “Help me set up NuGet trusted publishing for my library.”
- The agent will assess your repository's project files, guide you through creating the policy on nuget.org, and provide the necessary workflow configuration.
- “How do I migrate my existing NuGet publish workflow to use OIDC?”
- The agent will review your current workflow, suggest the required changes to permissions and login steps, and verify your nuget.org policy setup.
Install
Download the skill as a ZIP:
https://autogineer.com/agent-skills/dotnet/nuget-trusted-publishing/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip nuget-trusted-publishing.zip -d .agents/skills
Documentation by .NET (Microsoft)
NuGet Trusted Publishing Setup
Set up NuGet trusted publishing on a GitHub Actions repo. Replaces long-lived API keys with OIDC-based short-lived tokens — no secrets to rotate or leak.
Prerequisites
GitHub Actions — this skill covers GitHub Actions setup only
nuget.org account — the user needs access to create trusted publishing policies
When to Use This Skill
Use this skill when:
Setting up trusted publishing for a NuGet package
Migrating from
secrets.NUGET_API_KEYto OIDC-based publishingAsked about keyless or secure NuGet publishing
Creating a new NuGet publish workflow from scratch
Asked to "remove NuGet API key" or "use NuGet/login"
Setting up publishing for a dotnet tool, MCP server, or template package
Asked about
NuGet/login@v1orid-token: write
Safety Rules
⚠️ Bail-out rule: If any phase fails after one fix attempt on an infrastructure/auth issue, stop and ask the user. Don't loop on environment problems.
⚠️ Never delete or overwrite without confirmation: Removing API key secrets, deleting tags/releases, removing workflow steps, or changing package IDs. NuGet package IDs are permanent — mistakes can't be undone.
Process
Fast-path for greenfield repos: When the user has a simple setup (one packable project, no existing publish workflow), don't gate on multi-turn assessment. Combine phases: create the workflow immediately, include nuget.org policy guidance, local pack recommendation, and filename-matching warning all in one response. The full phased process below is for complex or migration scenarios.
Phase 1: Assess
Inspect the repo and report findings before making any changes.
Find and classify packable projects — check
.csprojfiles andDirectory.Build.props(package metadata is often set repo-wide). Classify in this order (earlier matches win):<PackageType>Template</PackageType>→ Template<PackageType>McpServer</PackageType>→ MCP server (also a dotnet tool)<PackAsTool>true</PackAsTool>→ Dotnet toolClass library (
IsPackable=trueor noOutputType) → Library<OutputType>Exe</OutputType>with<IsPackable>true</IsPackable>→ Application package (not a tool, but still publishable)<OutputType>Exe</OutputType>withoutPackAsToolorIsPackable→ Not packable by default (ask user if they intend to publish it)
Validate structure for each project's type:
Type Required All PackageId,Version(in .csproj or Directory.Build.props)Dotnet tool PackAsTool(required);ToolCommandName(optional but recommended — defaults to assembly name)MCP server PackageType=McpServer,.mcp/server.jsonincluded in packageTemplate PackageType=Template,.template.config/template.jsonunder content dirFind existing publish workflows in
.github/workflows/— look fordotnet nuget push,nuget push, ordotnet pack.Check version consistency — for MCP servers, verify
.csproj<Version>matches bothserver.jsonversion fields (rootversionandpackages[].version). Flag any mismatch.Report findings to the user: classification, missing properties, version mismatches, existing workflows. For multi-project repos, note whether one workflow or separate workflows per package are needed. Offer to fix gaps — use
ask_userbefore modifying project files.
❌ See references/package-types.md for per-type details and required properties.
Phase 2: Local Verification
Pack and verify locally before touching nuget.org — publishing errors waste a permanent version number.
⚠️ Always mention this step, even if you defer running it. Tell the user: "Before your first publish, run
dotnet pack -c Release -o ./artifactsto verify the .nupkg is created correctly."
dotnet pack -c Release -o ./artifacts— verify.nupkgis createdFor tools/MCP servers: install from
./artifacts, run--help, uninstallFor libraries: inspect the
.nupkgcontents (it's a zip)
Phase 3: nuget.org Policy
This phase requires the user to act on nuget.org — guide them with exact values.
Determine the repo owner, repo name, and the workflow filename that will publish.
❌ The policy requires the exact workflow filename (e.g.,
publish.ymlorpublish.yaml) — just the filename, no path prefix. Matching is case-insensitive. Don't use the workflowname:field.Guide the user to create the trusted publishing policy:
Go to nuget.org/account/trustedpublishing → Add policy
Repository Owner:
{owner}Repository:
{repo}Workflow File:
{filename}.ymlEnvironment:
release(only if the workflow usesenvironment:; leave blank otherwise)
Policy ownership: the user chooses individual account or organization. Org-owned policies apply to all packages owned by that org.
For private repos: policy is "temporarily active" for 7 days — becomes permanent after the first successful publish.
Guide the user to create a GitHub Environment (recommended but optional — provides secret scoping + approval gates):
Repo Settings → Environments → New environment →
releaseAdd environment secret: Name =
NUGET_USER, Value = nuget.org username (NOT email)Optional: add Required reviewers for an approval gate.
⚠️ Wait for the user to confirm they've created the policy before asking them to remove old API keys/secrets or before attempting to run/publish with the workflow. Drafting or showing the workflow file itself is OK before confirmation.
Phase 4: Workflow Setup
Create or modify the publish workflow. The workflow must always be created or shown in your response — you may draft/show it even if the nuget.org policy is not yet confirmed, but do not guide the user to actually run/publish or remove old secrets until after confirmation.
Greenfield: Create publish.yml from the template in references/publish-workflow.md. Adapt .NET version, project path, and environment name. Ensure your output explicitly mentions id-token: write and NuGet/login@v1.
Migration (existing workflow with API key): Modify in place —
Add OIDC permission and environment to the publishing job:
jobs: publish: environment: release permissions: id-token: write # Required — without this, NuGet/login fails with 403 contents: read # Explicit — setting permissions overrides defaultsAdd the NuGet login step before push:
- name: NuGet login (OIDC) id: login uses: NuGet/login@v1 with: user: ${{ secrets.NUGET_USER }} # nuget.org profile name, NOT emailReplace the API key in the push step:
--api-key ${{ steps.login.outputs.NUGET_API_KEY }} --skip-duplicateVerify: Ask the user to trigger a publish and confirm the package appears on nuget.org.
❌ Don't delete the old API key secret until trusted publishing is verified. Removing it is a one-way door — wait for confirmation.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
NuGet/login 403 | Missing id-token: write | Add to job permissions |
| "no matching policy" | Workflow filename mismatch | Verify exact filename on nuget.org |
| Push unauthorized | Package not owned by policy account | Check policy owner on nuget.org |
| Token expired | Login step >1hr before push | Move NuGet/login closer to push |
| "temporarily active" policy | Private repo, first publish pending | Publish within 7 days |
already_exists on push | Re-running same version | Add --skip-duplicate |
| GitHub Release 422 | Duplicate release for tag | Delete conflicting release (confirm first) |
| Re-run uses wrong YAML | gh run rerun replays original commit's YAML | Delete obstacle, re-run — never re-tag |
⚠️ If any blocker persists after one fix attempt, stop and ask the user.
References
Package type details: references/package-types.md — detection logic, required properties, minimal .csproj examples
Publish workflow template: references/publish-workflow.md — complete tag-triggered workflow ready to adapt
Microsoft docs: NuGet Trusted Publishing
Files
- ATTRIBUTION.mdAdded by AutoGineer863 B
- LICENSELicence file added by AutoGineer1.1 KiB
- SKILL.md9.1 KiB
- references/package-types.md8.2 KiB
- references/publish-workflow.md3.8 KiB
references/publish-workflow.md
Publish Workflow Template
Complete tag-triggered GitHub Actions workflow for publishing NuGet packages with trusted publishing. Copy and adapt to your repo.
Template
name: Publish to NuGet
on:
push:
tags:
- 'v*' # Triggers on version tags: v1.0.0, v1.2.3-preview.1, etc.
jobs:
publish:
runs-on: ubuntu-latest
environment: release # Uses release environment for secret scoping + protection rules
permissions:
id-token: write # Required for OIDC token (NuGet trusted publishing)
contents: read
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x' # Adjust to your target framework
- name: Extract version from tag
id: version
run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT
- name: Validate version matches project
run: |
PROJECT_VERSION=$(sed -n 's:.*<Version>\(.*\)</Version>.*:\1:p' path/to/YourProject.csproj)
if [ "$PROJECT_VERSION" != "${{ steps.version.outputs.VERSION }}" ]; then
echo "::error::Tag version (${{ steps.version.outputs.VERSION }}) doesn't match project version ($PROJECT_VERSION)"
exit 1
fi
- name: Pack
run: dotnet pack path/to/YourProject.csproj -c Release -o ./artifacts
- name: NuGet login (OIDC)
id: login
uses: NuGet/login@v1
with:
user: ${{ secrets.NUGET_USER }} # nuget.org profile name (NOT email)
- name: Push to NuGet
run: dotnet nuget push ./artifacts/*.nupkg --api-key ${{ steps.login.outputs.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicateCustomization Points
| Item | What to change |
|---|---|
dotnet-version | Match your TargetFramework |
path/to/YourProject.csproj | Path to your packable project |
Version extraction sed | Adjust for Directory.Build.props or .NET 10 file-based apps (#:property Version=) |
--skip-duplicate | Keeps push idempotent — safe for re-runs and matrix builds |
Release Process
Once the workflow is committed, the publish process is:
# 1. Bump version in .csproj (and server.json for MCP servers)
# 2. Commit
git add -A && git commit -m "Bump version to 0.1.0"
# 3. Tag and push
git tag v0.1.0
git push origin main --tags
# 4. Workflow runs automatically, publishes to nuget.orgOptional: GitHub Release Step
Add after the push step if you want GitHub Releases with the .nupkg attached. Note: this requires changing contents: read to contents: write in the job permissions.
- name: Create GitHub Release
uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v2
with:
files: ./artifacts/*.nupkg
generate_release_notes: true⚠️ Consider omitting this step entirely. Creating GitHub Releases separately (manually or via
gh release createin a different workflow) avoids 422already_existsconflicts and keeps the publish workflow focused on NuGet. If any release step fails, it blocks NuGet publishing too.
⚠️ Don't use
ncipollo/release-actionANDgh release createfor the same tag — this causes HTTP 422already_existserrors.
⚠️
gh run rerunreplays the original YAML from the tag commit, not frommain. If the workflow fails due to a release conflict, delete the conflicting release and re-run — don't delete the tag and re-tag (NuGet package IDs are permanent).
CI vs Publish Separation
Keep your CI workflow (build + test on PR/push) separate from the publish workflow (tag-triggered). This gives you:
CI runs on every PR without publishing
Publish only runs on deliberate version tags
Different permission scopes (CI doesn't need
id-token: write)
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Needs an MCP server, Needs an API key
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Published by
- .NET (Microsoft)
- Publisher
- .NET (Microsoft) (Official)
- Source
- dotnet/skills · plugins/dotnet-advanced/skills/nuget-trusted-publishing · commit 96c3d68
- Licence
- MIT License (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by .NET (Microsoft) or .NET (Microsoft).
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download nuget-trusted-publishing.zip