Export (0) Print
Expand All

Troubleshooting T4 Text Templates

Errors that arise while transforming and compiling the text template are reported in the Visual Studio error list in the usual manner. In most cases, line numbers in the template code are given in the error report. When the error report refers to a temporary filename, the usual cause is a mismatched bracket in the code of the text template.

To debug errors that occur when the text template code is executing, you can step through the code. To do this, you must add two lines to your template:

  • <#@template debug="true"#>

    If the template already contains a template directive, set the debug attribute in that directive.

  • <# System.Diagnostics.Debugger.Launch(); #>

    Insert this call near the beginning of the template code. When it is executed, you will be invited to debug the template using a new instance of Visual Studio. In this new instance, you can step through the template code using the F10 key.

  • If you want to re-enter the debugger later in the code, insert:

    <# System.Diagnostics.Debugger.Break(); #>

This procedure is described in more detail in the following topics.

Walkthrough: Debugging a Text Template

Describes how to debug a text template.

Common Errors and Warnings while using Text Templates

Lists the most common errors and warnings that are reported through the Error List window in Visual Studio.

Community Additions

ADD
Show:
© 2014 Microsoft