TypedRest.CodeGeneration.CSharp.SourceGenerator 0.1.0

dotnet add package TypedRest.CodeGeneration.CSharp.SourceGenerator --version 0.1.0
                    
NuGet\Install-Package TypedRest.CodeGeneration.CSharp.SourceGenerator -Version 0.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TypedRest.CodeGeneration.CSharp.SourceGenerator" Version="0.1.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TypedRest.CodeGeneration.CSharp.SourceGenerator" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="TypedRest.CodeGeneration.CSharp.SourceGenerator">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TypedRest.CodeGeneration.CSharp.SourceGenerator --version 0.1.0
                    
#r "nuget: TypedRest.CodeGeneration.CSharp.SourceGenerator, 0.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TypedRest.CodeGeneration.CSharp.SourceGenerator@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TypedRest.CodeGeneration.CSharp.SourceGenerator&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=TypedRest.CodeGeneration.CSharp.SourceGenerator&version=0.1.0
                    
Install as a Cake Tool

TypedRest Code Generation Source Generator

Roslyn source generator that builds TypedRest clients from OpenAPI/Swagger documents during compilation.

dotnet add package TypedRest.CodeGeneration.CSharp.SourceGenerator

Then reference the OpenAPI/Swagger document from your project file:

<ItemGroup>
  <TypedRestOpenApi Include="myapi.yml" ServiceName="MyService" Namespace="MyCompany.MyService" />
</ItemGroup>

The client is now part of your compilation:

var client = new MyServiceClient(new Uri("https://example.com/api/"));

For a walkthrough see the usage guide. This page is the reference for the configuration knobs and diagnostics.

Configuration

Each TypedRestOpenApi item supports the following metadata. Each can also be set as an MSBuild property (prefixed with TypedRest, e.g. $(TypedRestServiceName)) to provide a default for all spec files in a project.

Metadata Description Default
ServiceName The service name to use for the entry endpoint. Required.
Namespace The C# namespace for the endpoints. $(RootNamespace), else service name
DtoNamespace The C# namespace for the DTOs. the endpoint namespace
GenerateInterfaces Controls whether to generate interfaces for endpoints. true
GenerateDtos Controls whether to generate DTOs. true
LangVersion The minimum C# version the generated DTOs must compile with. the project's $(LangVersion)

Note that GenerateInterfaces and GenerateDtos default to true here, while the command-line tool requires them to be turned on explicitly. Generated endpoints reference the DTO types by name, so turning GenerateDtos off means you have to provide those types yourself.

To inspect the generated code set <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>; the files are then written to obj/.

Diagnostics

ID Severity Meaning
TRCG001 Error A TypedRestOpenApi item has no ServiceName and no $(TypedRestServiceName) fallback.
TRCG002 Error The OpenAPI document contains an error.
TRCG003 Warning The OpenAPI document contains something questionable.
TRCG004 Warning LangVersion is not a valid value; the project's language version is used instead.
TRCG005 Error Code generation failed for a document.
TRCG006 Warning The content of a spec file could not be read.

Limitations

  • The generator runs inside the compiler, so it requires a .NET SDK that ships Roslyn 5.6 or newer (.NET SDK 10.0.302+). Use the command-line tool for older toolchains.
  • Only local $refs are resolved. Bundle multi-file specs into a single document first.
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0 83 8/1/2026