Can I use T4 programmatically from C#?

為{幸葍}努か 提交于 2019-11-28 23:19:56

Oleg Sych describes how to do this here: Understanding T4: Preprocessed Text Templates. Note that it looks like you'll need Visual Studio 2010 to generate a preprocessed Text Template, but you'll be able to host the preprocessed Text Template wherever you like - including within your WinForms application.

A simple way to do this:

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();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!