Publish C# SDKs generated in Postman

View as Markdown

This guide covers publishing generated C# SDKs. For information on automating C# SDK publishing, see Publish C# SDKs automatically.

Publishing your SDK to NuGet.org makes it available to any .NET developer using dotnet add package.

Prerequisites

To publish your SDK to NuGet, you need the following:

  • A NuGet.org account.
  • An API key from your NuGet account settings.

Configure the project file

The generated [SdkName].csproj already includes the metadata required for publishing. Review and update the following fields before publishing.

1<Project Sdk="Microsoft.NET.Sdk">
2 <PropertyGroup>
3 <PackageId>YourSdk</PackageId>
4 <Version>1.0.0</Version>
5 <Authors>Your Name</Authors>
6 <Description>SDK for Your API</Description>
7 <PackageLicenseExpression>MIT</PackageLicenseExpression>
8 <PackageProjectUrl>https://github.com/your-org/your-sdk</PackageProjectUrl>
9 <RepositoryUrl>https://github.com/your-org/your-sdk</RepositoryUrl>
10 <TargetFramework>net6.0</TargetFramework>
11 </PropertyGroup>
12</Project>

Publish your C# SDK to NuGet

To publish your SDK to NuGet, do the following:

  1. Build and pack the SDK.

    $cd path/to/your-sdk
    $dotnet pack -c Release -o ./nupkgs
  2. Publish to NuGet.

    $dotnet nuget push ./nupkgs/YourSdk.1.0.0.nupkg \
    >--api-key YOUR_NUGET_API_KEY \
    >--source https://api.nuget.org/v3/index.json
  3. Verify the publication at https://www.nuget.org/packages/YourSdk. Packages are typically indexed within 15 to 30 minutes.

Publish updates

To publish updates to your SDK, run the following:

$# Update the version in your .csproj
$# Then pack and push
$dotnet pack -c Release -o ./nupkgs
$dotnet nuget push ./nupkgs/YourSdk.1.0.1.nupkg \
> --api-key YOUR_NUGET_API_KEY \
> --source https://api.nuget.org/v3/index.json

Best practices for publishing C# SDKs

Use the following best practices when publishing your C# SDK to NuGet:

  • Use semantic versioning.
  • Generate and include XML documentation by setting <GenerateDocumentationFile>true</GenerateDocumentationFile> in your .csproj file.
  • Tag releases in Git.
  • Include a .snupkg symbols package for debugging support by adding <IncludeSymbols>true</IncludeSymbols> and <SymbolPackageFormat>snupkg</SymbolPackageFormat>.