Text Template Transformation Toolkit


Text Template Transformation Toolkit is a free and open-source template based text generation framework included with Visual Studio. T4 source files are usually denoted by the file extension ".tt".

Overview

T4 is used by developers as part of an application or tool framework to automate the creation of text files with a variety of parameters. These text files can ultimately be any text format, such as code, XML, HTML or XAML.
T4 uses a custom template format which can contain.NET code and string literals in it, this is parsed by the T4 command line tool into.NET code, compiled and executed. The output of the executed code is the text file generated by the template. T4 can also be completely run within the.NET applications via the use of the TextTransformation class which eliminates the need for the end user to have Visual Studio installed.
T4 is used within Microsoft in ASP.NET MVC for the creation of the views and controllers, ADO.NET Entity Framework for entity generation, and ASP.NET Dynamic Data. It is also used outside of Microsoft in projects such as SubSonic.
T4 templating is also supported in MonoDevelop and JetBrains Rider.

Controls

There are four types of controls handed by the T4 template transformation engine.
NameSyntaxDescription
Directives<#@ ... #>Instructions for the transformation engine
Standard control blocks<# ... #>Code to be executed
Expression control blocks<#= ... #>Expressions evaluated and converted to a string
Class feature control blocks<#+ ... #>Class and function definitions

Criticism

Microsoft has often been criticized for the lack of tooling support for T4 within the Visual Studio IDE, and relies on third parties namely and , however later revisions have included better tooling support.

History