Share via


How to: Create Text Templates

A text template file contains a mixture of text blocks and control logic. Use the control logic to combine the text blocks with the data held within a model to produce an output file. There are a variety of uses for text templates. For example, you can use text templates to generate code or documentation from models. A text template contains both text block and control logic that are read along with the model by the text transformation engine. The engine processes the text template to create the appropriate output file that might be source code, xml, html, or some other deployable software artifact.

To create a new text template, follow the procedure below.

To create a new text template

  1. Open a domain-specific language project in Visual Studio.

  2. Press F5 to debug the project in the experimental build.

  3. Click Project, and then click Add New Item.

    The Add New Item dialog box appears.

  4. In the Templates pane, click Text File.

  5. In the Name box, type a name for your new text template, and then click Add.

    Note

    You can find example reporting text templates in the debugging project. These templates have the .tt file name extension. You can use any file name extension you want when you create a new text template, but .tt the one that is associated with text templates.

  6. Right-click the text file that you just added and then click Properties.

  7. Make sure that the Custom Tool property is set to TextTemplatingFileGenerator.

    A .cs file is generated and appears in Solution Explorer under the template file.

    You can now add code to the template file. For more information, see Adding Code to Text Templates. For a detailed example of adding functionality to a text template, see Walkthrough: Creating and Running Text Templates.

Security

For more information, see Security of Text Templates.

See Also

Concepts

How to: Run Text Templates

Basic Text Template Tasks

Using Built-in Directives in Text Templates