tags:

views:

201

answers:

2

I am using T4 templates in Visual Studio for code generation, and am trying to reference a local .xml file from the template code so I can parse it for metadata about the application's data model.

When the template code (which runs at compile time or when you run "Execute Custom Tool" on the template) tries to obtain the current path through Environment.CurrentDirectory, I get this:

c:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE

I'm really trying to find the path of the template itself, within the project, so that I can use relative pathing to find the .xml file that's driving it. Any ideas?

+2  A: 

I found the answer:

Path.GetDirectoryName(Host.TemplateFile)

blaster
+1  A: 

Another (perhaps a little quicker) way to do it is Host.ResolvePath(localFilePath).

Oleg Sych