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:
Configuration
Section titled “Configuration”To generate a C# SDK, add the csharp target to your Stainless configuration file:
targets: csharp: package_name: MyCompany.Client edition: csharp.2025-10-08Common configuration options
Section titled “Common configuration options”targets: csharp: package_name: MyCompany.Client
# Specify the edition edition: csharp.2025-10-08
# Configure publishing publish: nuget: trueFor a complete list of configuration options, see the C# target reference.
Strong named assemblies
Section titled “Strong named assemblies”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:
export TEMP_SNK=$(mktemp)sn -k $TEMP_SNKcat $TEMP_SNK | base64 -w 1000 # this is your base64-encoded assembly originator keysn -tp $TEMP_SNK | grep -oE '^[0-9a-f]+$' | tr -d '\n'; echo # this is your public keyrm $TEMP_SNK # cleanupOnce 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 keyWhen 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
Section titled “Editions”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)
Publishing to NuGet
Section titled “Publishing to NuGet”Publish your C# SDK to NuGet for distribution.
Get an API token
- Log in or sign up at NuGet.
- Select your username at the top right to open a dropdown.
- Navigate to API Keys.
- 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
- 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. - Add a new secret named
NUGET_API_KEYwith your API token.
Choose a package name and update your Stainless config
-
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>. -
Update the Stainless config with your package name and save.
targets:csharp:package_name: <package-name>publish:nuget: true