I've been messing around with T4 support in Mono and noticed a very cumbersome thing. The current directory when running T4 templates is the home directory. I need to be able to read a few files from the current project's directory but I'm at a loss for how to.
<#@ template language="C#v3.5" #>
<#@ output extension="txt" #>
<#=System.IO.Directory.GetCurrentDirectory() #>
yields
/home/earlz
where I want it to yield something like
/home/earlz/MyProject
How do I overcome this problem?
Also, I tried the hostspecific and Host.ResolvePath, but I got a NotImplementedException
Ok, think I've figured it out. You just have to actually resolve paths yourself. To get the directory of the template file(which is good enough for me) just use this:
<#= System.IO.Path.GetDirectoryName(Host.TemplateFile) #>
I fixed ResolvePath after your older question, along with a ton of other improvements. The fix should be in MonoDevelop 2.6, though you could try building from master.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With