How to get the project catalog from T4?

I was already messing around with T4 support in Mono and noticed a very cumbersome thing. The current directory when starting T4 templates is the home directory. I need to be able to read several files from the current project directory, but I do not understand how to do this.

<#@ template language="C#v3.5" #> <#@ output extension="txt" #> <#=System.IO.Directory.GetCurrentDirectory() #> 

gives

 /home/earlz 

where I want him to give something like

 /home/earlz/MyProject 

How do I solve this problem?

Also, I tried hostpecific and Host.ResolvePath, but I have a NotImplementedException

+4
source share
2 answers

Well, I think I figured it out. You just have to decide the paths yourself. To get the template file directory (which is good enough for me) just use this:

 <#= System.IO.Path.GetDirectoryName(Host.TemplateFile) #> 
+7
source

I fixed ResolvePath after your older question , as well as a ton of other improvements . The fix should be in MonoDevelop 2.6, although you can try building from the wizard .

+1
source

Source: https://habr.com/ru/post/1333770/


All Articles