17

我正在编写生成 C# 代码的软件。我主要使用StringTemplate和 StringBuilder。

有什么方法可以直接从我的代码中使用 T4 模板?

4

2 回答 2

11

Oleg Sych在此处描述了如何执行此操作:了解 T4:预处理文本模板。请注意,您似乎需要 Visual Studio 2010 来生成预处理的文本模板,但您可以在任何您喜欢的地方托管预处理的文本模板 - 包括在您的 WinForms 应用程序中。

于 2009-10-23T17:49:07.043 回答
5

一个简单的方法来做到这一点:

System.Diagnostics.Process proc = new System.Diagnostics.Process();

proc.EnableRaisingEvents = false;

// Set text transform program (this could change according to the Windows version)
proc.StartInfo.FileName = "C:\\Program Files (x86)\\Common Files\\microsoft shared\\TextTemplating\\10.0\\TextTransform.exe";

// Specify T4 template file
proc.StartInfo.Arguments = "C:\template.tt";

proc.Start();
于 2011-06-20T17:23:36.610 回答