是的,你可以。首先在T4包含文件中定義一個保存例程。
SaveOutput.tt:
<#@ template language=「C#」 hostspecific=「true」 #>
<#@ import namespace=「System.IO」 #>
<#+
void SaveOutput(string fileName)
{
string templateDirectory = Path.GetDirectoryName(Host.TemplateFile);
string outputFilePath = Path.Combine(templateDirectory, fileName);
File.WriteAllText(outputFilePath, this.GenerationEnvironment.ToString());
this.GenerationEnvironment.Remove(0, this.GenerationEnvironment.Length);
}
#>
現在每次調用SaveOutput一個文件名時,將寫入當前緩衝區到外部文件。例如。
Web.tt:
<#@ include file=「SaveOutput.tt」 #>
<#
GenerateConfig();
SaveOutput(」..\..\Web.Config」);
#>
如果要生成多個文件:
<#@ include file=「SaveOutput.tt」 #>
<#
GenerateFile1();
SaveOutput(」..\..\File1.txt」);
GenerateFile2();
SaveOutput(」..\..\File2.txt」);
#>
我能問爲什麼這有差別? –
http://nuget.codeplex.com/workitem/1210 – Sly
不是很乾淨,但您可以從項目中刪除web.tt並使用TextTransform.exe創建web.config文件(http://msdn.microsoft.com/ en-us/library/bb126245.aspx)作爲預先或後期構建操作?最終這似乎是nuget的一個問題,但是當你在等待bug修復時,也許這可以減輕你的痛苦。 – FuleSnabel