0

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?

ackh
  • 1,648
  • 2
  • 18
  • 36
  • Can't you just use `Path.ChangeExtension(Host.TemplateFile, ".cs")`? – Klaus Gütter Nov 13 '21 at 07:14
  • I've written a `.ttinclude` file containing common functionality used by several T4 templates. That `.ttinclude` file is unaware of the file extension that is defined by the including T4 template. It should just be able to get it from the parent, not set it. So, I cannot use `Path.ChangeExtension(Host.TemplateFile, ".cs")`. – ackh Nov 13 '21 at 07:43
  • 1
    Maybe you should add this information to your question. – Klaus Gütter Nov 13 '21 at 08:45

0 Answers0