我正在尝试构建一个模板,该模板将在不同的文件夹中创建一系列文件,但我没有找到任何示例。
问问题
2254 次
1 回答
4
您可以使用RenderToFile
from t4Toolbox来执行此操作。
截至 2016.10.12 的文档示例的片段:
使用两个 C# 类库项目 ClassLibrary1.csproj 和 ClassLibrary2.csproj 创建一个 Visual Studio 解决方案。
将一个名为 CodeGenerator.tt 的新代码生成文件添加到第一个类库项目中。
将新文件的内容修改为如下所示
<#@ template language="C#" hostspecific="True" debug="True" #>
<#@ output extension="txt" #>
<#@ include file="T4Toolbox.tt" #>
<#
SampleTemplate template = new SampleTemplate();
template.Output.File = @"SubFolder\SampleOutput.txt";
template.Output.Project = @"..\ClassLibrary2\ClassLibrary2.csproj";
template.Render();
#>
<#+
public class SampleTemplate : Template
{
public override string TransformText()
{
this.WriteLine("Hello, World!");
return this.GenerationEnvironment.ToString();
}
}
#>
于 2012-04-17T10:52:08.550 回答