I'm trying to build a template that will create a series of files in different folders but I haven't found any samples.
You can use RenderToFile
from t4Toolbox to do this.
Snippet from documentation example as of 2016.10.12:
Create a Visual Studio solution with two C# Class Library projects ClassLibrary1.csproj and ClassLibrary2.csproj.
Add a new code generation file called CodeGenerator.tt to the first class library project.
Modify contents of the new file to look like so
<#@ 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();
}
}
#>
Original Documentation
Wayback Machine
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With