HoofMark · Open Source

C# code generation
that stays in your IDE

cstemplate lets you write code generators as ordinary C# files, with full IntelliSense, go-to-definition, and compile-time checking — no string templates, no external DSL, no build pipeline required.

Install CLI
$ dotnet tool install --global HoofMark.CSharpTemplating.Cli

Templates are just C# classes

Write a class that implements ITemplate, run it with the VS Code extension or CLI, and generated files appear on disk. No magic, no configuration language to learn.

Template
MyTemplate.template.cs
Config / Model
MyTemplate.json
C#
Output
Generated .cs files

Full IntelliSense

Templates compile as part of your project. C# Dev Kit gives you completions, refactoring, and error squiggles as you type.

📦

NuGet aware

Reference any NuGet package in your templates — including packages with native dependencies like Microsoft.Data.SqlClient.

🗂️

Model file support

Read XML, JSON, or any file format with context.ReadFile(). Relative paths resolve from the template directory automatically.

🔒

Isolated execution

Each template runs in its own AssemblyLoadContext. No conflicts between templates or between template and host dependencies.

🖥️

VS Code integration

Right-click any .template.cs file to run it. Compile errors appear as inline diagnostics. Output panel shows what was generated.

🔧

CLI first

The cstemplate CLI works standalone — integrate with any build pipeline, CI system, or editor.

Up and running in minutes

Three steps from install to generated code.

Install the CLI tool and VS Code extension

Install the global dotnet tool, then install the VS Code extension from the marketplace.

$ dotnet tool install --global HoofMark.CSharpTemplating.Cli

Add the abstractions package to your project

<PackageReference Include="HoofMark.CSharpTemplating.Abstractions"
                  Version="1.0.0" />

Write your first template

Create a .template.cs file anywhere in your project:

using HoofMark.CSharpTemplating.Abstractions;

namespace MyProject.Templates;

public class OrderServiceTemplate : ITemplate
{
    public static void Run(ITemplateContext context)
    {
        var ns = context.Config.Get("Namespace");

        context.WriteFile("OrderService.cs", w => w
            .WriteLine($"namespace {ns};")
            .Block("public class OrderService", body => body
                .WriteLine("// Generated by cstemplate")
            ));
    }
}

Right-click the file in VS Code and choose Run Template, or run from the terminal:

$ cstemplate run OrderServiceTemplate.template.cs

cstemplate.config.json

Place a cstemplate.config.json file in your project folder (or any parent folder) to control output location, NuGet packages, and local references.

{
  "outputRoot": "../generated",
  "project":    "./MyProject.csproj",
  "nugetPackages": [
    "Humanizer.Core",
    "Microsoft.Data.SqlClient"
  ],
  "references": [
    "path/to/LocalAssembly.dll"
  ]
}
FieldDescription
outputRoot Output directory for generated files, relative to this config file.
project Path to the .csproj file. Required when using nugetPackages.
nugetPackages NuGet package IDs to make available in templates. Versions and transitive dependencies are resolved from dotnet restore.
references Paths to local .dll assemblies, relative to this config file.
SettingDefaultDescription
cstemplate.cliPathcstemplatePath to the cstemplate CLI executable.
cstemplate.checkOnSavetrueCompile-check templates on save, showing errors as diagnostics.
cstemplate.showOutputOnRuntrueShow output panel when a template is run.
cstemplate.outputRootemptyDefault output root. Falls back to generated/ next to each template.
cstemplate.templateFilePattern**/*.template.csGlob pattern used to identify template files.

Reference & guides

Full API reference, CLI documentation, and configuration guides.