Comments in T4 Templates

To include comments as part of control code, they need to be inside a code block of some sort, for example

<# // Hello this is a comment #>

or

<#+ // Hello this is a comment in a class feature block #>

Sometimes you need to push the close tag to the next line if you're sensitive to extra newlines in the output.

If you want to comment out whole blocks of markup, there isn't a straightforward solution unfortunately, and the result gets rather ugly.

You can do it by escaping the tags that you'd like to comment, like so:

\<# my control code \#>

and then placing that inside a comment in another block like so:

<# // \<# my control code \#> #>

The best way to add block comment is to use #if and #endif

<#
   #if false
   foreach(var typeName in typeNames)
   { 
       var className = typeName + "Adapter";
#>
    // ...
<#  
    }
    #endif
#>