Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

T4 output filename

Tags:

t4

t4-toolbox

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?

like image 712
Simon Avatar asked Aug 10 '11 17:08

Simon


2 Answers

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")#>
like image 79
Just another metaprogrammer Avatar answered Sep 28 '22 01:09

Just another metaprogrammer


It better to define it as a directive

for example for a xaml file

<#@ output extension="xaml" #>

or for txt

<#@ output extension=".txt" #>
like image 37
404Dreamer_ML Avatar answered Sep 28 '22 00:09

404Dreamer_ML