This documentation is archived and is not being maintained.

How to: Debug Text Templates 

Visual Studio 2005

One of the common uses for domain-specific languages is to generate code and other artifacts from models. Domain-Specific Language Tools use text templates to generate code, xml, reports, or other artifacts from models. A text template is a file containing a mixture of text blocks and control logic used to combine the text blocks with the data held within a model to produce an output file.

To enable debugging, set the debug parameter of the template directive, as explained in the following procedure.

To set the debug parameter of the template directive

  1. In Solution Explorer, right-click the text template file you want to edit and then click Open.

    The template opens in the editor.

  2. Add the following template and import directives to the template:

    <#@ template debug="true" #>
    <#@ import namespace="System.Diagnostics" #>

    The template directive contains a debug parameter, and we have set the parameter to true. Setting the debug parameter to true causes the engine to add the underlying source and .pdb files needed to enable debugging.

  3. Insert a Debugger.Break statement in the text template where you want to insert a breakpoint as shown below:

    <# Debugger.Break(); #>

    <# Debugger.Break() #>

  4. In Solution Explorer, in the project node, right-click the text template file and click Run Custom Tool.

    The break statement will execute and you will either be prompted for a debugging session or be taken to the applicable line of code.


For more information, see Security of Text Templates.

See Also