我有一个运行时T4模板,使用它我生成一个.cs文件。我需要在我的代码中访问这个生成的文件。我没有看到生成的类文件,所以我可以使用它,但如果我做一个“显示所有文件”,然后将其包含在我的解决方案,并建立我然后能够访问生成的文件。在生成中包含T4生成的c#类
如何使用此生成的c#文件,而无需手动进行任何更改。
它应该像我使用的代码
RuntimeTextTemplate runTimeGen = new RuntimeTextTemplate();
File.WriteAllText("RuntimeGenerator3.cs", runTimeGen.TransformText());
的最后一条语句我应该能够访问生成的类后,对不对? 是模板文件。我正在使用控制台应用程序。
运行时模板的名称是RuntimeGenerator.tt
<#@ template language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
namespace Controls
{
public class DropDownControlUtility
{
public static string ForeColor
{
get
{
return "Blue";
}
}
}
}
类与主方法包括下面
class Program
{
static void Main(string[] args)
{
RuntimeGenerator gen = new RuntimeGenerator();
File.WriteAllText("DropDownUtility.cs", gen.TransformText());
}
}
你可以显示你的模板,你如何生成文件? – 2014-12-03 07:11:15