2
這裏繼insructions http://www.olegsych.com/2008/03/how-to-generate-multiple-outputs-from-single-t4-template/爲什麼我的Visual Studio T4代碼輸出錯誤?
我試圖從test1.tt通過VAR PERSONNAME到template1.tt,但我看不到任何文件,爲什麼?
template1.tt
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ import namespace="System.IO" #>
<#@ output extension=".txt" #>
<#@ assembly name="System"#>
hello <#= personName #>
TEST1 .tt
<#@ template language="C#" hostspecific="True" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="Microsoft.VisualStudio.TextTemplating" #>
<#@ import namespace="System.Runtime.Remoting.Messaging" #>
CallContext.SetData("template1.personName", "Baby");
ProcessTemplate("template1.tt","testoutput.txt");
<#+
void ProcessTemplate(string templateFileName, string outputFileName) {
string templateDirectory = Path.GetDirectoryName(Host.TemplateFile);
string outputFilePath = Path.Combine(templateDirectory, outputFileName);
string template = File.ReadAllText(Host.ResolvePath(templateFileName));
Engine engine = new Engine();
string output = engine.ProcessTemplate(template, Host);
File.WriteAllText(outputFilePath, output);
}
#>
究竟是什麼錯誤,你會得到什麼? – cdhowie 2011-01-09 19:16:05