我有一個名爲ParentTemplate的T4模板,它包含另一個名爲ChildTemplate的T4模板。這個想法是我的ParentTemplate被調用並且每次調用ChildTemplate時都會生成一個文件。但是,我的ParentTemplate也創建了一個我不需要的文件(.cs)。 ParentTemplate的Build Action設置爲「None」,Custom Tool設置爲「TextTemplatingFileGenerator」。下面的代碼是從ParentTemplate:T4模板生成不需要的輸出文件
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ import namespace="System.IO" #>
<#
for (int i = 0; i < 3; i++)
{
#>
<#@ include file="ChildTemplate.t4" #>
<#
string filename = Path.Combine(path, String.Format("{0}i.txt", myFile));
File.WriteAllText(filename, this.GenerationEnvironment.ToString());
this.GenerationEnvironment.Remove(0, this.GenerationEnvironment.Length);
}
#>
在ChildTemplate僅僅是文本 「Hello World」。所以我想要的輸出是3個.txt文件,內容爲「Hello World」,就是這樣。所以沒有像ParentTemplate.cs這樣的其他文件。
任何想法如何防止生成ParentTemplate.cs?