Getting the location of a .tt file in T4
Question
Using T4 I want to generate some code based on examining what files are in a directory relative to the template file being executed.
Is there a way in c# to identify what the path of the current template file is?
Solution
You need to set the hostspecific property of the template directive to True. This will make T4 generate a special property called Host, which gives you access to ResolvePath method and TemplateFile property. You can find details here: http://www.olegsych.com/2008/02/t4-template-directive/
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow