Skip to content
FeedbackDashboard
Codegen targets

C#

Generate production-ready C# SDKs from your OpenAPI specification

The Stainless C# SDK generator creates idiomatic, type-safe C# client libraries from your OpenAPI specification.

Example repositories:

To generate a C# SDK, add the csharp target to your Stainless configuration file:

targets:
csharp:
package_name: MyCompany.Client
edition: csharp.2025-10-08
targets:
csharp:
package_name: MyCompany.Client
# Specify the edition
edition: csharp.2025-10-08
# Configure publishing
publish:
nuget: true

For a complete list of configuration options, see the C# target reference.

Strong-named assemblies are a .NET mechanism to give assemblies a unique ID. This provides several benefits, including the ability to have your assembly installed in the global assembly cache.

To enable strong-named assemblies, you will need a base64-encoded assembly originator key and corresponding public key. You can generate these keys on a Linux or Mac system (or on WSL) using the following commands:

Terminal window
export TEMP_SNK=$(mktemp)
sn -k $TEMP_SNK
cat $TEMP_SNK | base64 -w 1000 # this is your base64-encoded assembly originator key
sn -tp $TEMP_SNK | grep -oE '^[0-9a-f]+$' | tr -d '\n'; echo # this is your public key
rm $TEMP_SNK # cleanup

Once you have your keys, add them to your Stainless config like so:

targets:
csharp:
...
strong_name:
originator_key: foo # your base64-encoded assembly originator key
public_key: bar # your public key

When you add those keys to your Stainless config, an Open.snk file will be added to your C# repository automatically, and strong-name signing will be enabled at build and publish time.

Editions allow Stainless to make improvements to SDKs that aren’t backwards-compatible. You can explicitly opt in to new editions when you’re ready. See the SDK and config editions reference for more information.

csharp.2025-10-08

  • Initial edition for C# (used by default if no edition is specified)

Publish your C# SDK to NuGet for distribution.

Get an API token
  1. Log in or sign up at NuGet.
  2. Select your username at the top right to open a dropdown.
  3. Navigate to API Keys.
  4. Create a new API key with the Push new packages and package versions privilege. Under Select Packages, either enter your package name or a glob (e.g. ”*”).
Add the token to your production repo
  1. In your production repo, navigate to Secrets and variables > Actions > New repository secret. The URL should look like https://github.com/<org>/<repo>/settings/secrets/actions/new.
  2. Add a new secret named NUGET_API_KEY with your API token.
Choose a package name and update your Stainless config
  1. Choose an available package name. Suggested names are:

    • <company-name>
    • <company-name>.Client

    You can check whether the name is available by testing the link at https://www.nuget.org/packages/<package-name>.

  2. Update the Stainless config with your package name and save.

    targets:
    csharp:
    package_name: <package-name>
    publish:
    nuget: true