C# (NuGet)

The C# target is experimental.

The C# target publishes to NuGet. The package id is the target's packageName reduced to a PascalCase .NET identifier: acme-api and Acme.Api both publish as AcmeApi. See the C# configuration for options.

Authenticate the release with OIDC trusted publishing (recommended) or a NuGet API key.

Enable publishing

{
  "targets": {
    "csharp": {
      "packageName": "AcmeApi",
      "publish": { "nuget": true }
    }
  }
}

Trusted publishing (OIDC)

Recommended. The release workflow uses the NuGet/login action to exchange the workflow's identity token for a short-lived API key, so no long-lived key is stored. NuGet's OIDC login still needs your profile name as one secret.

Add a trusted publishing policy on NuGet

On nuget.org, open your username → Trusted Publishing and add a policy for:

  • Package owner: you, or an organization you are an active member of
  • Repository owner and name: your linked repository
  • Workflow file: release-please.yml
  • Environment: publish.nuget.releaseEnvironment, or blank when none is set

The policy's scopes and package glob decide whether it may publish a package that does not exist yet: select the scope that allows publishing new packages, and a glob the package id matches, or the first release is rejected.

The automated publish runs as the publish job inside release-please.yml, so that is the workflow NuGet sees. If you also dispatch sdk-release.yml to re-publish a tag by hand, add it as a second policy.

A new policy is sometimes only provisionally active for 7 days (nuget.org says this usually happens for a private repository); the first successful publish inside that window makes it permanent. You can restart the window at any time, including after it lapses.

Add your NuGet username as a secret

Add a repository secret named NUGET_USER set to your nuget.org profile name (not your email). See Adding repository secrets. This is the only secret OIDC needs; the API key itself is issued at publish time.

Keep the default config
{ "targets": { "csharp": { "publish": { "nuget": true } } } }

Publishing with a NuGet API key

Create a NuGet API key

On nuget.org, go to API Keys → Create, give it the scope to push new packages and package versions with a glob that matches your package id, and copy the key.

Add it to the repository

Add the key as a repository secret named NUGET_API_KEY. See Adding repository secrets. When publish.nuget.releaseEnvironment is set, an environment secret of the same name overrides the repository one.

Switch the target to token auth
{
  "targets": {
    "csharp": {
      "publish": { "nuget": { "authMethod": "access-token" } }
    }
  }
}

Notes

  • The workflow pushes with --skip-duplicate, so re-publishing an existing version is a no-op.
  • With options.strongName set, commit the .snk key at its keyFile path to the integration branch before the first release. The generator never writes the key, and packing without it fails the publish job after release-please has already tagged the release. A tag cut without the key cannot be re-published, because both release-please.yml and sdk-release.yml build the tagged commit; commit the key, and the next release publishes signed.

What did you think of this content?