Search code examples
t4t4-toolbox

T4 output filename


How can i use generated file's name in template? I'd like to something like this:

// This file: <#= OutputFileName #> was autogenerated

How can i do that in T4 or in T4Toolbox?


Solution

  • This seemed like something that should be as simple as reading a property but after reflecting over the Host variable and disassembling the text generator code I think the simplest way of doing this is:

    <#@ template language="C#" hostspecific="true"  #>
    <#@ import namespace="System.IO"                #>
    
    // <#=Path.ChangeExtension (Host.TemplateFile, "cs")#>