How to: Create Text Templates
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
Open a domain-specific language project in Visual Studio.
Press F5 to debug the project in the experimental build.
Click Project, and then click Add New Item.
The Add New Item dialog box appears.
In the Templates pane, click Text File.
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.
In Solution Explorer, select the text file that you just added.
Click the Categorized icon in the Properties window toolbar and expand the Advanced category.
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. For a detailed example of adding functionality to a text template, see .
To debug text templates you must set the debug parameter of the template directive. For more information, see.
For more information, see.