Text Template Transformation Toolkit

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search
Text Template Transformation Toolkit (T4)
Original authorsNovell, Xamarin, Microsoft
Initial release2005; 21 years ago (2005)
Stable release
v2.0.5 / June 13, 2019; 7 years ago (2019-06-13)[1]
Repositorygithub.com/mono/t4
Written inC#
Engine
    Lua error in Module:EditAtWikidata at line 29: attempt to index field 'wikibase' (a nil value).
    Operating systemLinux, Windows
    Platform.NET Framework,
    .NET Core,
    Mono
    TypeSoftware framework
    LicenseMIT License
    WebsiteCode Generation and T4 Text Templates

    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

    [edit | edit source]

    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.[2] 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.[3] It is also used outside of Microsoft in projects such as SubSonic.[4]

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

    Controls

    [edit | edit source]

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

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

    History

    [edit | edit source]
    • 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.[6]
    • 2015: Visual Studio 2015 Update 2 can use C# version 6.0 features[7]
    • 2017: Open source version of engine released which supports .NET Core[8]
    • 2019: JetBrains adds support for T4 in Rider[9]

    See also

    [edit | edit source]

    Lua error in mw.title.lua at line 392: bad argument #2 to 'title.new' (unrecognized namespace name 'Portal').

    References

    [edit | edit source]
    1. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    2. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    3. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    4. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    5. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    6. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    7. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    8. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    9. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    [edit | edit source]