Поскольку я хотел создать несколько файлов с использованием шаблонов T4, я добавил файл шаблона T4 в проект библиотеки классов (.NET Core) (.net Core 2.1).

Я добавил следующий код в шаблон T4.
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System" #>
<#@ import namespace="System.IO" #>
<#@ output extension=".txt" #>
<#
for (Int32 i = 0; i < 5; ++i) {
#>
Content <#= i #>
<#
// End of file.
SaveOutput("Content" + i.ToString() + ".txt");
}
#>
<#+
private void SaveOutput(string outputFileName) {
string templateDirectory = Path.GetDirectoryName(Host.TemplateFile);
string outputFilePath = Path.Combine(templateDirectory, outputFileName);
File.WriteAllText(outputFilePath, this.GenerationEnvironment.ToString());
this.GenerationEnvironment.Remove(0, this.GenerationEnvironment.Length);
}
#>
Как и ожидалось, было создано 5 текстовых файлов.

Однако файлы, созданные из шаблона, не вложены в файл «Generated.Files.tt».Как мы вложили эти файлы в «Generated.Files.tt», поэтому, если я раскрою файл tt, я бы хотел увидеть сгенерированные файлы.