|
1 | 1 | --- |
2 | | -title: Publishing to Nuget |
3 | | -description: How to publish the Fern .NET SDK to Nuget. |
| 2 | +title: Publishing to NuGet |
| 3 | +description: How to publish the Fern .NET SDK to NuGet. |
4 | 4 | --- |
5 | 5 |
|
6 | | -Learn how to publish your Fern .NET SDK to the Nuget registry. |
| 6 | +Publish your public-facing Fern C#/.NET SDK to the [NuGet |
| 7 | +registry](https://www.nuget.org/). After following the steps on this page, |
| 8 | +you'll have a versioned package published on NuGet. |
7 | 9 |
|
8 | | -<Warning>This page is a WIP, please refer to our previous [documentation](https://buildwithfern.com/learn/sdks/guides/publish-a-public-facing-sdk).</Warning> |
| 10 | + |
| 11 | +<Frame> |
| 12 | + <img src="assets/dotnet-package.png" alt="Versioned package published on NuGet" /> |
| 13 | +</Frame> |
| 14 | + |
| 15 | +<Info>This guide assumes that you already have an initialized `fern` folder on your local machine. If you don’t, run `fern init`. See [.NET Quickstart](quickstart.mdx) for more details.</Info> |
| 16 | + |
| 17 | +## Set up your GitHub integration |
| 18 | + |
| 19 | + 1. Create a new GitHub repository called `company-csharp` (or something similar) for your SDK, if you haven't done so already. |
| 20 | + 1. Install the [Fern GitHub App](https://github.com/apps/fern-api): Select **Configure**, then scroll down to **Repository Access**. Select **Only select repositories** and in the dropdown select the repository for your SDK. Click **Save**. |
| 21 | + |
| 22 | + |
| 23 | +## Configure `generators.yml` |
| 24 | + |
| 25 | +<Steps> |
| 26 | + |
| 27 | + <Step title="Run `fern add <generator>`"> |
| 28 | + |
| 29 | + 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. |
| 30 | + |
| 31 | + Add a new generator to `generators.yml`: |
| 32 | + |
| 33 | + |
| 34 | + ```bash |
| 35 | + fern add fern-csharp-sdk --group csharp-sdk |
| 36 | + ``` |
| 37 | + |
| 38 | + Once the command completes, you'll see a new group created in your `generators.yml`: |
| 39 | + |
| 40 | + ```yaml {3-9} |
| 41 | + groups: |
| 42 | + ... |
| 43 | + csharp-sdk: |
| 44 | + generators: |
| 45 | + - name: fernapi/fern-csharp-sdk |
| 46 | + version: <Markdown src="/snippets/version-number.mdx"/> |
| 47 | + output: |
| 48 | + location: local-file-system |
| 49 | + path: ../sdks/csharp |
| 50 | + ``` |
| 51 | + |
| 52 | + </Step> |
| 53 | + |
| 54 | + <Step title="Configure `output` location"> |
| 55 | + |
| 56 | + 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: |
| 57 | + |
| 58 | + ```yaml {6-7} |
| 59 | + groups: |
| 60 | + csharp-sdk: |
| 61 | + generators: |
| 62 | + - name: fernapi/fern-csharp-sdk |
| 63 | + version: <Markdown src="/snippets/version-number.mdx"/> |
| 64 | + output: |
| 65 | + location: nuget |
| 66 | + |
| 67 | + ``` |
| 68 | + </Step> |
| 69 | + |
| 70 | + <Step title="Add a unique package name"> |
| 71 | + |
| 72 | + 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: |
| 73 | + |
| 74 | + |
| 75 | +```yaml {8} |
| 76 | +groups: |
| 77 | + csharp-sdk: |
| 78 | + generators: |
| 79 | + - name: fernapi/fern-csharp-sdk |
| 80 | + version: <Markdown src="/snippets/version-number.mdx"/> |
| 81 | + output: |
| 82 | + location: nuget |
| 83 | + package-name: your-package-name |
| 84 | +``` |
| 85 | + |
| 86 | + </Step> |
| 87 | + <Step title="Configure `client-class-name`"> |
| 88 | + |
| 89 | + 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';`). |
| 90 | + |
| 91 | + |
| 92 | +```yaml {9-10} |
| 93 | +groups: |
| 94 | + csharp-sdk: |
| 95 | + generators: |
| 96 | + - name: fernapi/fern-csharp-sdk |
| 97 | + version: <Markdown src="/snippets/version-number.mdx"/> |
| 98 | + output: |
| 99 | + location: nuget |
| 100 | + package-name: your-package-name |
| 101 | + config: |
| 102 | + client_class_name: YourClientName # must be PascalCase |
| 103 | +``` |
| 104 | + |
| 105 | + </Step> |
| 106 | + |
| 107 | + <Step title="Add repository location"> |
| 108 | + |
| 109 | + Add the path to your GitHub repository to `generators.yml`: |
| 110 | + |
| 111 | +```yaml {11-12} |
| 112 | +groups: |
| 113 | + csharp-sdk: |
| 114 | + generators: |
| 115 | + - name: fernapi/fern-csharp-sdk |
| 116 | + version: <Markdown src="/snippets/version-number.mdx"/> |
| 117 | + output: |
| 118 | + location: nuget |
| 119 | + package-name: your-package-name |
| 120 | + config: |
| 121 | + client_class_name: YourClientName |
| 122 | + github: |
| 123 | + repository: your-org/company-csharp |
| 124 | +``` |
| 125 | + |
| 126 | + </Step> |
| 127 | + </Steps> |
| 128 | + |
| 129 | +## Set up NuGet publishing authentication |
| 130 | + |
| 131 | +<Steps> |
| 132 | + |
| 133 | + <Step title="Log into NuGet"> |
| 134 | + |
| 135 | + Log into [NuGet](https://nuget.org/) or create a new account. |
| 136 | + |
| 137 | + </Step> |
| 138 | + |
| 139 | + <Step title="Add New Key"> |
| 140 | + |
| 141 | + 1. Click on your profile picture. |
| 142 | + 1. Select **API Keys**, then **Create**. |
| 143 | + 1. Name your key. |
| 144 | + 1. Select **Push > Push new packages and package versions** as the **Select Scopes** type. |
| 145 | + 1. Enter `*` under **Select Packages > Glob Patten**. |
| 146 | + |
| 147 | + <Tip title="Replacing an existing NuGet package"> |
| 148 | + If you are overriding an existing package, you can select the relevant |
| 149 | + package instead of entering `*`. |
| 150 | + </Tip> |
| 151 | + 1. Click **Create**. |
| 152 | + |
| 153 | + <Frame> |
| 154 | + <img src="assets/new-api-key.png" alt="Creating a New API Key" /> |
| 155 | + </Frame> |
| 156 | + |
| 157 | + <Warning>Save your new key – it won’t be displayed after you leave the page.</Warning> |
| 158 | + |
| 159 | + </Step> |
| 160 | + |
| 161 | + <Step title="Configure NuGet authentication key"> |
| 162 | + |
| 163 | + 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. |
| 164 | + |
| 165 | +```yaml {9} |
| 166 | +groups: |
| 167 | + csharp-sdk: |
| 168 | + generators: |
| 169 | + - name: fernapi/fern-csharp-sdk |
| 170 | + version: <Markdown src="/snippets/version-number.mdx"/> |
| 171 | + output: |
| 172 | + location: nuget |
| 173 | + package-name: your-package-name |
| 174 | + api-key: ${NUGET_API_KEY} |
| 175 | + config: |
| 176 | + client_class_name: YourClientName |
| 177 | + github: |
| 178 | + repository: your-org/company-csharp |
| 179 | +``` |
| 180 | + </Step> |
| 181 | + |
| 182 | +</Steps> |
| 183 | + |
| 184 | +## Release your SDK to NuGet |
| 185 | + |
| 186 | + At this point, you're ready to generate a release for your SDK. |
| 187 | + |
| 188 | +<Steps> |
| 189 | + |
| 190 | + <Step title="Set NuGet environment variable"> |
| 191 | + |
| 192 | + On your local machine, set the `NUGET_API_KEY` environment variable to the new API key you generated earlier: |
| 193 | + |
| 194 | + ```bash |
| 195 | + export NUGET_API_KEY=your-actual-nuget-key |
| 196 | + ``` |
| 197 | + |
| 198 | + </Step> |
| 199 | + |
| 200 | + <Step title="Generate your release"> |
| 201 | + |
| 202 | + Regenerate your SDK and publish it on NuGet: |
| 203 | + |
| 204 | + ```bash |
| 205 | + fern generate --group csharp-sdk --version <version> |
| 206 | + ``` |
| 207 | + Local machine output will verify that the release is pushed to your |
| 208 | + repository and tagged with the version you specified. Log back into NuGet and |
| 209 | + navigate to **Packages** to see your new release. |
| 210 | + </Step> |
| 211 | + |
| 212 | +</Steps> |
0 commit comments