Generated banner for Nuget Trusted Publishing
Generated logo for Nuget Trusted Publishing

Nuget Trusted Publishing

.NET (Microsoft)OfficialPublished by .NET (Microsoft)

  • Skill
  • Tool integration
  • Software development
  • MIT
  • No issues found

From the author

Set up NuGet trusted publishing (OIDC) on a GitHub Actions repo — replaces long-lived API keys with short-lived tokens. USE FOR: trusted publishing, NuGet OIDC, keyless NuGet publish, migrate from NuGet API key, NuGet/login, secure NuGet publishing. DO NOT USE FOR: publishing to private feeds or Azure Artifacts (OIDC is nuget.org only). INVOKES: shell (powershell or bash), edit, create, ask_user for guided repo setup.
— the description by .NET (Microsoft)

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

  1. Download the skill as a ZIP:

    https://autogineer.com/agent-skills/dotnet/nuget-trusted-publishing/download
  2. Unzip 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_KEY to 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@v1 or id-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.

  1. Find and classify packable projects — check .csproj files and Directory.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=true or no OutputType) → Library

    • <OutputType>Exe</OutputType> with <IsPackable>true</IsPackable> → Application package (not a tool, but still publishable)

    • <OutputType>Exe</OutputType> without PackAsTool or IsPackable → Not packable by default (ask user if they intend to publish it)

  2. Validate structure for each project's type:

    TypeRequired
    AllPackageId, Version (in .csproj or Directory.Build.props)
    Dotnet toolPackAsTool (required); ToolCommandName (optional but recommended — defaults to assembly name)
    MCP serverPackageType=McpServer, .mcp/server.json included in package
    TemplatePackageType=Template, .template.config/template.json under content dir
  3. Find existing publish workflows in .github/workflows/ — look for dotnet nuget push, nuget push, or dotnet pack.

  4. Check version consistency — for MCP servers, verify .csproj <Version> matches both server.json version fields (root version and packages[].version). Flag any mismatch.

  5. 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_user before 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 ./artifacts to verify the .nupkg is created correctly."

  1. dotnet pack -c Release -o ./artifacts — verify .nupkg is created

  2. For tools/MCP servers: install from ./artifacts, run --help, uninstall

  3. For libraries: inspect the .nupkg contents (it's a zip)

Phase 3: nuget.org Policy

This phase requires the user to act on nuget.org — guide them with exact values.

  1. Determine the repo owner, repo name, and the workflow filename that will publish.

    ❌ The policy requires the exact workflow filename (e.g., publish.yml or publish.yaml) — just the filename, no path prefix. Matching is case-insensitive. Don't use the workflow name: field.

  2. 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 uses environment:; 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.

  3. Guide the user to create a GitHub Environment (recommended but optional — provides secret scoping + approval gates):

    Repo Settings → Environments → New environment → release

    Add 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 —

  1. 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
  2. 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
  3. Replace the API key in the push step:

    --api-key ${{ steps.login.outputs.NUGET_API_KEY }} --skip-duplicate
  4. 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

ProblemCauseFix
NuGet/login 403Missing id-token: writeAdd to job permissions
"no matching policy"Workflow filename mismatchVerify exact filename on nuget.org
Push unauthorizedPackage not owned by policy accountCheck policy owner on nuget.org
Token expiredLogin step >1hr before pushMove NuGet/login closer to push
"temporarily active" policyPrivate repo, first publish pendingPublish within 7 days
already_exists on pushRe-running same versionAdd --skip-duplicate
GitHub Release 422Duplicate release for tagDelete conflicting release (confirm first)
Re-run uses wrong YAMLgh run rerun replays original commit's YAMLDelete obstacle, re-run — never re-tag

⚠️ If any blocker persists after one fix attempt, stop and ask the user.

References

Files

references/package-types.md

NuGet Package Type Reference

Structural requirements for each NuGet package type. The agent uses this to validate a repo's packaging setup before configuring trusted publishing.

Detection Logic

Inspect .csproj files (and Directory.Build.props if present) for these MSBuild properties:

1. Has <PackageType>Template</PackageType>?           → Template package
2. Has <PackageType>McpServer</PackageType>?           → MCP server (also a dotnet tool)
3. Has <PackAsTool>true</PackAsTool>?                  → Dotnet tool
4. Has <IsPackable>true</IsPackable> or no OutputType? → NuGet library
5. Has <OutputType>Exe</OutputType> + <IsPackable>true</IsPackable>? → Application package
6. Has <OutputType>Exe</OutputType> without PackAsTool or IsPackable? → Not packable by default (ask user)

Check in order — MCP servers have PackAsTool too, so PackageType must be checked first.

NuGet Library

The most common case. A class library consumed via PackageReference.

Required Properties
PropertyExampleNotes
PackageIdContoso.UtilitiesDefaults to AssemblyName if omitted
Version0.1.0Start with 0.x for initial development
PropertyPurpose
AuthorsPackage author(s)
DescriptionShown on nuget.org
PackageTagsDiscoverability
PackageReadmeFileREADME displayed on nuget.org
PackageLicenseExpressionSPDX license identifier
RepositoryUrlLink back to source
PublishRepositoryUrlEnables source-link integration
Including README in Package

PackageReadmeFile alone isn't enough — you must also include the file in the package:

<PropertyGroup>
  <PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
<ItemGroup>
  <None Include="README.md" Pack="true" PackagePath="/" />
  <!-- If README is in a parent dir (common for src/ layouts): -->
  <!-- <None Include="../../README.md" Pack="true" PackagePath="/" /> -->
</ItemGroup>
Minimal .csproj
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net9.0</TargetFramework>
    <PackageId>Contoso.Utilities</PackageId>
    <Version>0.1.0</Version>
    <Authors>Contoso</Authors>
    <Description>Utility library for Contoso apps</Description>
    <PackageReadmeFile>README.md</PackageReadmeFile>
  </PropertyGroup>
  <ItemGroup>
    <None Include="README.md" Pack="true" PackagePath="/" />
  </ItemGroup>
</Project>
Pack Command
dotnet pack -c Release

Dotnet Tool

A console app distributed as a global or local tool via dotnet tool install.

Required Properties
PropertyExampleNotes
OutputTypeExeMust be an executable
PackAsTooltrueMarks this as a tool package
PackageIdcontoso-cliTool package identifier
Version0.1.0Package version (or set in Directory.Build.props)
PropertyExampleNotes
ToolCommandNamecontosoCommand users type; defaults to assembly name
PackageOutputPath./nupkgWhere .nupkg is written
PackageReadmeFileREADME.mdShown on nuget.org
Minimal .csproj
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net9.0</TargetFramework>
    <PackAsTool>true</PackAsTool>
    <ToolCommandName>contoso</ToolCommandName>
    <PackageId>contoso-cli</PackageId>
    <PackageReadmeFile>README.md</PackageReadmeFile>
  </PropertyGroup>
  <ItemGroup>
    <None Include="README.md" Pack="true" PackagePath="/" />
  </ItemGroup>
</Project>
Pack Command
dotnet pack -c Release

MCP Server

A dotnet tool that implements the Model Context Protocol. Distributed the same way as a dotnet tool but with additional metadata for MCP client discovery.

Naming Convention

Follow the established pattern for MCP server packages:

  • PackageId: {github-username}.{domain}.mcp (e.g., lewing.helix.mcp)

  • server.json name: io.github.{username}/{packageid} (e.g., io.github.lewing/lewing.helix.mcp)

Required Properties

Everything from Dotnet Tool, plus:

PropertyExampleNotes
PackageTypeMcpServerNuGet recognizes this as an MCP server
PropertyExampleNotes
McpServerJsonTemplateFile.mcp/server.jsonMCP client discovery metadata
Required Files
FilePurpose
.mcp/server.jsonMCP server descriptor for client discovery

The .mcp/server.json must be included in the package:

<ItemGroup>
  <None Include=".mcp/server.json" Pack="true" PackagePath="/.mcp/" />
</ItemGroup>
Minimal server.json
{
  "$schema": "https://static.modelcontextprotocol.io/schemas/2025-10-17/server.schema.json",
  "name": "io.github.contoso/contoso.services.mcp",
  "description": "MCP server for Contoso services",
  "version": "0.1.0",
  "packages": [
    {
      "registryType": "nuget",
      "registryBaseUrl": "https://api.nuget.org",
      "identifier": "contoso.services.mcp",
      "version": "0.1.0",
      "transport": { "type": "stdio" }
    }
  ]
}

⚠️ Version sync: The version fields in server.json MUST match the <Version> in your .csproj. Update both when bumping versions.

⚠️ nuget.org MCP Server tab: nuget.org auto-generates MCP install config from your server.json. If your tool requires a subcommand (e.g., my-tool mcp), the generated config may omit it. Ensure your tool defaults to MCP server mode when invoked with no arguments, or uses a --yes flag for non-interactive acceptance.

Minimal .csproj
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net9.0</TargetFramework>
    <PackAsTool>true</PackAsTool>
    <PackageType>McpServer</PackageType>
    <PackageId>contoso.services.mcp</PackageId>
    <ToolCommandName>contoso-mcp</ToolCommandName>
    <McpServerJsonTemplateFile>.mcp/server.json</McpServerJsonTemplateFile>
    <PackageReadmeFile>README.md</PackageReadmeFile>
  </PropertyGroup>
  <ItemGroup>
    <None Include=".mcp/server.json" Pack="true" PackagePath="/.mcp/" />
    <None Include="README.md" Pack="true" PackagePath="/" />
  </ItemGroup>
</Project>

Template Package

A package containing dotnet new templates.

Required Properties
PropertyExampleNotes
PackageTypeTemplateNuGet recognizes this as a template package
PackageIdContoso.TemplatesTemplate package identifier
Required Files
FilePurpose
content/*/.template.config/template.jsonTemplate definition — one per template

The template.json must include at minimum: identity, name, shortName, tags.type (item or project).

Minimal .csproj
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <PackageType>Template</PackageType>
    <PackageId>Contoso.Templates</PackageId>
    <Version>0.1.0</Version>
    <Description>Contoso project templates</Description>

    <!-- Template packages should not build code -->
    <IncludeContentInPack>true</IncludeContentInPack>
    <IncludeBuildOutput>false</IncludeBuildOutput>
    <ContentTargetFolders>content</ContentTargetFolders>
    <NoDefaultExcludes>true</NoDefaultExcludes>
  </PropertyGroup>
  <ItemGroup>
    <Content Include="content/**" />
  </ItemGroup>
</Project>

Common Gotchas

  • IsPackable defaults: Class libraries default to true, console apps to false. Console apps can still be published as NuGet packages by setting <IsPackable>true</IsPackable> — they just won't be installable via dotnet tool install unless PackAsTool is also set.

  • Directory.Build.props: Package metadata may be set at the repo root — always check there too.

  • Multi-project repos: A repo may contain multiple packable projects of different types. Each needs its own trusted publishing workflow or a matrix build.

  • GeneratePackageOnBuild: If true, dotnet build also produces the .nupkg. The workflow should use dotnet pack explicitly for clarity.

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