Text Template Transformation Toolkit Explained

Text Template Transformation Toolkit (T4)
Author:Novell, Xamarin, Microsoft
Latest Release Version:v2.0.5
Latest Release Date:[1]
Programming Language:C#
Operating System:Linux, Windows
Platform:.NET Framework,
.NET Core,
Mono
Genre:Software framework
License:MIT License

Text Template Transformation Toolkit (usually referred to as "T4") is a free and open-source 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 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, 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. 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 for the creation of the views and controllers, ADO.NET Entity Framework for entity generation, and ASP.NET Dynamic Data.[2] It is also used outside of Microsoft in projects such as SubSonic.[3]

T4 templating is supported in Visual Studio, MonoDevelop and JetBrains Rider.[4]

Controls

There are four types of controls handled by the T4 template transformation engine.

NameSyntaxDescription
Directives<#@&nbsp;...&nbsp;#>Instructions for the transformation engine
Standard control blocks<#&nbsp;...&nbsp;#>Code to be executed (e.g. loops)
Expression control blocks<#=&nbsp;...&nbsp;#>Expressions evaluated and converted to a string
Class feature control blocks<#+&nbsp;...&nbsp;#>Class and function definitions

History

See also

External links

Notes and References

  1. Web site: Tags · mono/t4 · GitHub. GitHub T4 repository. en. 2020-01-06.
  2. Web site: Fun with T4 templates and Dynamic Data - Angle Bracket Percent - Site Home - MSDN Blogs . Blogs.msdn.com . 2008-11-26 . 2012-05-17.
  3. Web site: SubSonic v3's T4 Templates « Daily Cycle . Gcapnias.wordpress.com . 2009-01-12 . 2012-05-17.
  4. Web site: Rider: The Cross-Platform .NET IDE from JetBrains.
  5. Web site: What's new in T4 in Visual Studio 2010 - [Profoundly Esoteric Image&#93; - Site Home - MSDN Blogs |publisher=Blogs.msdn.com |date=2010-04-15 |access-date=2012-05-17].
  6. Web site: Code Generation and T4 Text Templates - Visual Studio (Windows).
  7. Web site: Mono.TextTemplating. . 22 October 2021.
  8. Web site: ForTea. . 20 October 2021.