Publishing to NuGet

Publish your public-facing Fern C#/.NET SDK to the NuGet registry. After following the steps on this page, you’ll have a versioned package published on NuGet.

Versioned package published on NuGet
This guide assumes that you already have an initialized fern folder on your local machine. See Set up the fern folder for more details.

Set up your GitHub integration

  1. Create a new GitHub repository called company-csharp (or something similar) for your SDK, if you haven’t done so already.
  2. Install the Fern GitHub App: Select Configure, then scroll down to Repository Access. Select Only select repositories and in the dropdown select the repository for your SDK. Click Save.

Configure generators.yml

1

Run fern add <generator>

Navigate to your generators.yml on your local machine. Your generators.yml lives inside of your fern folder and contains all the configuration for your Fern generators.

Add a new generator to generators.yml:

$fern add fern-csharp-sdk --group csharp-sdk

Once the command completes, you’ll see a new group created in your generators.yml:

1 groups:
2 ...
3 csharp-sdk:
4 generators:
5 - name: fernapi/fern-csharp-sdk
6 version: 2.1.1
7 output:
8 location: local-file-system
9 path: ../sdks/csharp
2

Configure output location

Next, change the output location in generators.yml from local-file-system (the default) to nuget to indicate that Fern should publish your package directly to the NuGet registry:

1groups:
2 csharp-sdk:
3 generators:
4 - name: fernapi/fern-csharp-sdk
5 version: 2.1.1
6 output:
7 location: nuget
3

Add a unique package name

Your package name must be unique in the NuGet repository, otherwise publishing your SDK to NuGet will fail. Update your package name if you haven’t done so already:

1groups:
2 csharp-sdk:
3 generators:
4 - name: fernapi/fern-csharp-sdk
5 version: 2.1.1
6 output:
7 location: nuget
8 package-name: your-package-name
4

Configure client-class-name

The client-class-name option controls the name of the generated client. This is the name customers use to import your SDK (import { your-client-name } from 'your-package-name';).

1groups:
2 csharp-sdk:
3 generators:
4 - name: fernapi/fern-csharp-sdk
5 version: 2.1.1
6 output:
7 location: nuget
8 package-name: your-package-name
9 config:
10 client_class_name: YourClientName # must be PascalCase
5

Add repository location

Add the path to your GitHub repository to generators.yml:

1groups:
2 csharp-sdk:
3 generators:
4 - name: fernapi/fern-csharp-sdk
5 version: 2.1.1
6 output:
7 location: nuget
8 package-name: your-package-name
9 config:
10 client_class_name: YourClientName
11 github:
12 repository: your-org/company-csharp

Set up NuGet publishing authentication

1

Log into NuGet

Log into NuGet or create a new account.

2

Add New Key

  1. Click on your profile picture.

  2. Select API Keys, then Create.

  3. Name your key.

  4. Select Push > Push new packages and package versions as the Select Scopes type.

  5. Enter * under Select Packages > Glob Patten.

    Replacing an existing NuGet package

    If you are overriding an existing package, you can select the relevant package instead of entering *.

  6. Click Create.

Creating a New API Key
Save your new key – it won’t be displayed after you leave the page.
3

Configure NuGet authentication key

Add api-key: ${NUGET_API_KEY} to generators.yml to tell Fern to use the NUGET_API_KEY environment variable for authentication when publishing to the NuGet registry.

1groups:
2 csharp-sdk:
3 generators:
4 - name: fernapi/fern-csharp-sdk
5 version: 2.1.1
6 output:
7 location: nuget
8 package-name: your-package-name
9 api-key: ${NUGET_API_KEY}
10 config:
11 client_class_name: YourClientName
12 github:
13 repository: your-org/company-csharp

Release your SDK to NuGet

At this point, you’re ready to generate a release for your SDK.

1

Set NuGet environment variable

On your local machine, set the NUGET_API_KEY environment variable to the new API key you generated earlier:

$export NUGET_API_KEY=your-actual-nuget-key
2

Generate your release

Regenerate your SDK and publish it on NuGet:

$fern generate --group csharp-sdk --version <version>

Local machine output will verify that the release is pushed to your repository and tagged with the version you specified. Log back into NuGet and navigate to Packages to see your new release.