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 me开发者_StackOverflow中文版tadata 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?
I found the answer:
Path.GetDirectoryName(Host.TemplateFile)
Another (perhaps a little quicker) way to do it is Host.ResolvePath(localFilePath).
精彩评论