【发布时间】:2016-10-03 16:00:04
【问题描述】:
我正在使用 t4 模板并面临以下问题。我需要在我的模板中包含另一个现有的 t4 模板。但我有一个限制:包含的 t4 模板文件的名称是动态生成的。
我为此使用了include 指令,但它不起作用。
<#@ include file="\Helpers\<# FileName.tt#>" #>
我收到一个错误:
An unexpected start or end tag was found within a block. Make sure that you did not mis-type a start or end tag, and that you do not have any nested blocks in the template.
属性FileName的值是动态生成的
【问题讨论】:
-
为什么要生成 T4?我想不出任何附加步骤有意义的场景。
-
@Toxantron,我有一些 t4 模板文件。并且取决于情况,我应该将其中之一包含到我的模板中。但是包含哪一个是由配置文件决定的。
-
你试过了吗?
<#@ include file=string.Format(@"\Helpers\{0}.tt", FileName) #> -
是的,但没用。
-
我认为这里没有办法使用include,因为在我看来,include是在编译时解决的。是运行时模板吗?