t4
T4 text template processor for code generation
TLDR
SYNOPSIS
t4 [options] [template]
DESCRIPTION
t4 is a command-line tool for processing T4 (Text Template Transformation Toolkit) templates, a general-purpose way to use C# to generate any kind of text or code files. It is part of Mono.TextTemplating, a modern open-source reimplementation of the Visual Studio T4 text templating engine.The tool operates in two modes: direct template processing, which generates output files immediately, and preprocessing, which converts templates into runtime template classes that can be embedded in applications and executed at runtime.Templates use C# code blocks delimited by <# and #> tags to emit dynamic content. Parameter directives support automatic type conversion from CLI string values to the type specified in the template. The tool can read templates from standard input and write output to standard output, enabling pipeline integration.
PARAMETERS
-o file
Output file path; use - for stdout-p:name=value
Pass a parameter value to the template (repeatable)-c classname
Preprocess template into a runtime template class-r assembly
Reference an assembly-u namespace
Import a namespace-I directory
Add an include search directory--dp processor!class!assembly
Add a custom directive processor--help
Show help message--version
Show version information
CAVEATS
Requires the .NET SDK (6.0 or later) to be installed. Install the tool globally with dotnet tool install -g dotnet-t4. Different from the original Visual Studio T4 engine in some edge cases. Templates written for Visual Studio may need minor adjustments for full compatibility.
HISTORY
T4 (Text Template Transformation Toolkit) originated as part of Visual Studio for code generation. The Mono.TextTemplating project reimplemented the engine as an open-source, cross-platform alternative and has since evolved to include many improvements over the original, including support for the latest .NET APIs and C# language features. The command-line tool was first released as a .NET global tool in 2020.
