Text Template Transformation Toolkit (usually referred to as "T4") is a
free and open-source
Free and open-source software (FOSS) is software available under a Software license, license that grants users the right to use, modify, and distribute the software modified or not to everyone free of charge. FOSS is an inclusive umbrella term ...
template-based text generation framework. 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
A framework is a generic term commonly referring to an essential supporting structure which other things are built on top of.
Framework may refer to:
Computing
* Application framework, used to implement the structure of an application for an op ...
to automate the creation of text files with a variety of parameters. These text files can ultimately be any text format, such as code (for example
C#),
XML
Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing data. It defines a set of rules for encoding electronic document, documents in a format that is both human-readable and Machine-r ...
,
HTML
Hypertext Markup Language (HTML) is the standard markup language for documents designed to be displayed in a web browser. It defines the content and structure of web content. It is often assisted by technologies such as Cascading Style Sheets ( ...
or
XAML
Extensible Application Markup Language (XAML ) is a declarative XML-based language developed by Microsoft for initializing structured values and objects. It is available under Microsoft's Open Specification Promise.
XAML is used extensively i ...
.
T4 uses a custom template format which can contain .NET code and
string literal
string literal or anonymous string is a literal for a string value in the source code of a computer program. Modern programming languages commonly use a quoted sequence of characters, formally "bracketed delimiters", as in x = "foo", where , "foo ...
s 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.
By using the Text Transformation class, T4 can also be run entirely from within a .NET application, eliminating the need for the end user to have Visual Studio installed.
T4 is used within Microsoft in
ASP.NET MVC
ASP.NET MVC is a web application framework developed by Microsoft that implements the model–view–controller (MVC) pattern. It is no longer in active development. It is open-source software, apart from the ASP.NET Web Forms component, which is ...
for the creation of the views and controllers,
ADO.NET Entity Framework
Entity Framework (EF) is an open source object–relational mapping (ORM) framework for ADO.NET. It was originally shipped as an integral part of .NET Framework, however starting with Entity Framework version 6.0 it has been delivered separatel ...
for entity generation, and
ASP.NET Dynamic Data. It is also used outside of Microsoft in projects such as SubSonic.
T4 templating is supported in
Visual Studio
Visual Studio is an integrated development environment (IDE) developed by Microsoft. It is used to develop computer programs including web site, websites, web apps, web services and mobile apps. Visual Studio uses Microsoft software development ...
,
MonoDevelop
MonoDevelop (also known as Xamarin Studio) is a discontinued open-source integrated development environment for Linux, macOS, and Windows. Its primary focus is development of projects that use Mono and .NET Framework. MonoDevelop integrates feat ...
and JetBrains Rider.
Controls
There are four types of controls handled by the T4 template transformation engine.
History
* 2005: Microsoft released the first version of T4 as an out-of-band release for Visual Studio 2005
* 2008: Microsoft includes it with Visual Studio 2008
* 2010: Microsoft includes it with Visual Studio 2010 which included significant new features to improve performance, usability for both template authors and tool builders and better integration into Visual Studio's DSL tools.
* 2015: Visual Studio 2015 Update 2 can use C# version 6.0 features
* 2017: Open source version of engine released which supports
.NET Core
* 2019: JetBrains adds support for T4 in Rider
See also
*
Comparison of code generation tools
List of tools
Technical features
References
{{DEFAULTSORT:Code Generation Tools, Comparison Of
Programming tools
Code generation tools
Source code generation ...
*
m4 (computer language)
m4 is a general-purpose macro processor included in most Unix-like operating systems, and is a component of the POSIX standard.
The language was designed by Brian Kernighan and Dennis Ritchie for the original versions of UNIX. It is an extensio ...
*
Smarty
References
External links
GitHub - mono/t4: T4 text templating engine
{{DEFAULTSORT:Visual Studio
.NET
Free and open-source software
Microsoft free software
Microsoft Visual Studio
Software that uses Mono (software)
Software using the MIT license
Template engines
2005 software
2008 software
2010 software