Freigeben über


How to: Debug Text Templates

You can use domain-specific languages 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.

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. You will either be prompted for a debugging session or you will be moved to the applicable line of code.

Security

For more information, see Security of Text Templates.

See Also

Concepts

Troubleshooting Text Templates

Walkthrough: Debugging a Text Template

Common Validation Errors and Warnings in Text Templates