How can I access the name of the T4 output file via code?

358 Views Asked by At

Visual Studio's T4 templates offer the Output Directive which allows me to specify the file extension of the generated file as follows:

<#@ output extension=".cs" #>

I would like to access that file extension from the code within the T4 template so that I can get the entire filename of the file that is generated. I can get the name of the T4 template itself via Host property as follows:

string templateName = Path.GetFileName(Host.TemplateFile);

But I don't see how to get the file extension or entire name of the T4 output file ("MyTemplate.cs" in that case if the T4 is named "MyTemplate.tt"). I can't find any property on the Host that seems helpful here. Does anyone know?

0

There are 0 best solutions below