用T4获取项目或相关目录 [英] Get Project or Relative Directory with T4

查看:169
本文介绍了用T4获取项目或相关目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从t4模板中获取对Visual Studio项目或解决方案的目录或t4模板的目录的引用?

How can I get a reference to the directory of the visual studio project or solution or the directory of the t4 template from within a t4 template?

我有一个将相对于模板位于一起的多个文件连接在一起的模板。我需要通过一个相对的方法来获得对绝对位置的引用。硬编码的绝对路径是不可接受的,因为Visual Studio项目不会总是在相同的位置,这将打破代码生成。从环境中读取当前工作目录不起作用,因为它返回T4引擎所在的位置而不是模板。

I have a template that concatenates a number of files together which are located relative to the template. I need to get a reference to there absolute location through a relative means. Hard coding an absolute path is not acceptable because the visual studio project will not always be in the same location and this would break the code generation. Reading the current working directory from the environment doesn't work either because that returns the location of where the T4 engine lives not the template. I'm just getting in to t4 so any help would be appreciated.

推荐答案

请参阅主机特定参数 strong>部分 HERE

See The Host Specific Parameter section HERE.

这段代码展示了如何获得src相对于模板的完整路径。

This snippet shows how to get the full path of src relative to the template.

<#@ template hostspecific="true" #>
// The location of the src folder relative to the t4 template:
// <#= Host.ResolvePath("src") #>

这篇关于用T4获取项目或相关目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆