This was way harder to figure out than it should have been, so for the next person that needs to reference an input file in a T4 template by its relative path, here is what you need to do…
1. Include T4Toolbox.tt…
<#@ include file=”T4Toolbox.tt” #>
2. Add hostspecific=”True” to your template setting…
<#@ template language=”C#” hostspecific=”True” #>
3. Import EnvDTE…
<#@ import namespace=”EnvDTE” #>
4. Now TransformationContext.Host.ResolvePath(“SomeFile.sdf”) will return the absolute path of “SomeFile.sdf”.

2 comments
Comments feed for this article
July 8, 2009 at 3:54 pm
Perry
I’m storing some of the raw data in text form within the project, which are sql statements that need to be applied to both Sql Server and Oracle. The whole project is in source control. Thus, being able to identify the directory of the tt file is essential.
I was not able to find this info anywhere else. Thanks very much.
November 25, 2009 at 11:49 am
Marcus
Awesome, thanks!! I almost stored my data as resources in a different assembly, just to get around this problem.