Export (0) Print
Expand All

How to: Create Text Templates 

Visual Studio 2005

A text template file contains a mixture of text blocks and control logic. The control logic is used 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, 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 another 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 text box, enter a name for your new text template and then click Add.


    Example reporting text templates are provided in the debugging project. These templates have the .reporttemplate extension. You are free to use any extension you want when you create a new text template.

  6. In Solution Explorer, select the text file that you just added.

  7. Click the Categorized icon in the Properties window toolbar and expand the Advanced category.

  8. Under Advanced, set the Custom Tool property to a value of TextTemplatingFileGenerator and then press ENTER.

    A .cs file is generated and appears in Solution Explorer under the template file that you created earlier.

    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.


    To debug text templates you must set the debug parameter of the template directive. For more information, see How to: Debug Text Templates.


For more information, see Security of Text Templates.

See Also

Community Additions

© 2014 Microsoft