.N .NET Landscape

Mono.TextTemplating (T4)

Source Generators & Metaprogramming
github.com/mono/t4

T4 text templating engine

GitHub stars
439
Forks
109
Open issues
58
NuGet downloads
609,941,432
latest 3.0.0
Language
C#
Last push
1 year ago
15 Nov 2024
Created
16 Mar 2017

Mono.TextTemplating

Build NuGet version (dotnet-t4)

T4 templates are a simple general-purpose way to use C# to generate any kind of text or code files.

Mono.TextTemplating started out as an open-source reimplementation of the Visual Studio T4 text templating engine, but has since evolved to have many improvements over the original, including support for C# 10 and .NET 6.

The dotnet-t4 tool can be used either to process T4 templates directly, or preprocess them into runtime template classes that can be included in your app and processed at runtime.

$ dotnet tool install -g dotnet-t4
$ echo "<#@ parameter name='Name' #>Hello <#=Name#>" | t4 -o - -p:Name=World
Hello World

To learn more, see the dotnet-t4 readme.

For advanced use, the engine itself is available as a package called Mono.TextTemplating that can be embedded in an app. For details, see the Mono.TextTemplating package readme.