Getting the location of a .tt file in T4

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?

11.12.2008 18:55:24

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:

29.12.2008 15:15:57
Hello, I would like to ask you whether your code is still (in 2015) only one existing solution. I found simpler and in run-time functional piece of code [var namespaceName = System.Runtime.Remoting.Messaging.CallContext.LogicalGetData("NamespaceHint") as string;] but this code does not work when debugging T4 template (tested in VS 2012).
user2126375 30.05.2015 14:03:36
I'm confused how this is simpler than setting the hostspecific flag... There are always going to be many possible solutions, but enabling the Host property gives you a lot of functionality to simplify output file management.
Chris Schaller 8.01.2016 02:29:34