t4

T4 template whitespace control


Are there any commands to easily control T4 template output whitespace? I'm getting some excessive tabbing. I thought I remembered a way to control template whitespace...


Solution

  • PushIndent, PopIndent, ClearIndent http://msdn.microsoft.com/en-us/library/bb126474.aspx

    Do not format your template for readability. Any white space you have outside of control block will end up in the output

    for(int i=0; i < 10; i++) 
    {
       #>
         Hello
        <#
    }
    

    will end up as

       Hello
          Hello
          Hello
          Hello
          Hello
          Hello