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.1 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
There are four types of controls handled by the T4 template transformation engine.
Web Templates (2013), Website templates, Website Templates South Africa, ISBN 978-1-4251-3374-0, retrieved 19 November 2013 978-1-4251-3374-0 ↩
"Fun with T4 templates and Dynamic Data - Angle Bracket Percent - Site Home - MSDN Blogs". Blogs.msdn.com. 2008-11-26. Retrieved 2012-05-17. http://blogs.msdn.com/b/davidebb/archive/2008/11/26/fun-with-t4-templates-and-dynamic-data.aspx ↩
"SubSonic v3's T4 Templates « Daily Cycle". Gcapnias.wordpress.com. 2009-01-12. Retrieved 2012-05-17. http://gcapnias.wordpress.com/2009/01/12/subsonic-v3%e2%80%99s-t4-templates/ ↩
"Rider: The Cross-Platform .NET IDE from JetBrains". https://www.jetbrains.com/rider/ ↩
"What's new in T4 in Visual Studio 2010 - [Profoundly Esoteric Image] - Site Home - MSDN Blogs". Blogs.msdn.com. 2010-04-15. Retrieved 2012-05-17. http://blogs.msdn.com/b/garethj/archive/2010/04/15/what-s-new-in-t4-in-visual-studio-2010.aspx ↩
"Code Generation and T4 Text Templates - Visual Studio (Windows)". 12 January 2024. https://docs.microsoft.com/en-us/visualstudio/modeling/code-generation-and-t4-text-templates ↩
"Mono.TextTemplating". GitHub. 22 October 2021. https://github.com/mono/t4 ↩
"ForTea". GitHub. 20 October 2021. https://github.com/jetbrains/fortea ↩