
NuGet Trusted Publishing
FreeSecurely publish NuGet packages without API keys.
Free · Opens the source repo
What NuGet Trusted Publishing does
NuGet Trusted Publishing is designed to facilitate secure package publishing on nuget.org by leveraging OpenID Connect (OIDC). This skill helps users set up a GitHub Actions repository to replace long-lived API keys with short-lived tokens, enhancing security by eliminating the need for secrets that can be leaked or require regular rotation. It is particularly useful for developers looking to establish a trusted publishing workflow for their NuGet packages.
The skill provides a structured approach to setting up trusted publishing, guiding users through a multi-phase process. Initially, it assesses the repository to identify packable projects and existing workflows, ensuring that all necessary metadata is present before any changes are made. This assessment phase is critical for users migrating from traditional API key-based publishing or those creating new workflows from scratch.
Once the assessment is complete, users are guided through local verification to ensure that their packages are correctly built before attempting to publish them. This step is essential to prevent wasting version numbers on failed publishes. The skill then assists users in creating the required trusted publishing policy on nuget.org, detailing the necessary parameters such as repository ownership and workflow filenames.
Finally, the skill helps set up the GitHub Actions workflow needed for publishing. It emphasizes safety by implementing strict rules against unintended deletions or overwrites, ensuring that users confirm significant changes before proceeding. This makes NuGet Trusted Publishing a reliable choice for developers who want to streamline their package publishing process while maintaining a high level of security.
When to use it
Use this skill when setting up or migrating to a trusted publishing workflow for NuGet packages on nuget.org.
When not to use it
This skill is not suitable for publishing to private feeds or Azure Artifacts, as it is specifically designed for nuget.org.
What you can build with it
Migrating from API Keys
Transitioning from using long-lived API keys to OIDC-based publishing for enhanced security.
Setting Up a New Package
Creating a new NuGet package workflow from scratch with trusted publishing enabled.
Verifying Package Structure
Ensuring that all necessary metadata and configurations are in place before publishing a NuGet package.
How to install NuGet Trusted Publishing
View source1. Install with the skills CLI
npx skills add dotnet/skills/nuget-trusted-publishing --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by dotnetNuGet 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 publishing - Asked 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 tool- Class 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 dir -
Find 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 created- For tools/MCP servers: install from
./artifacts, run--help, uninstall - For 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}.yml - Environment:
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.
- Repository Owner:
-
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 defaults -
Add 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 email -
Replace the API key in the push step:
--api-key ${{ steps.login.outputs.NUGET_API_KEY }} --skip-duplicate -
Verify: 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
Frequently asked questions about NuGet Trusted Publishing
Similar skills
Turborepo
Optimized build system for JavaScript/TypeScript monorepos.
Azure Pipelines Validation
Streamline your Azure DevOps pipeline changes locally.
Azure Developer CLI
Streamline your Azure project workflows with best practices.
Azure Container Registry CLI
Manage Azure Container Registry resources with ease.
Aspire
Build and orchestrate polyglot distributed applications seamlessly.
Vercel CLI
Manage and deploy Vercel projects from the command line.
