Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running T4 templates from other T4 template

does anyone know if it's possible to run T4 template file from another T4 template, inside VS2010

Thank

like image 964
muek Avatar asked Sep 03 '10 13:09

muek


People also ask

What is transform all T4 templates?

t4 is basically a tool built into VS for doing text transformation, typically for doing code generation. Transform All T4 Templates searches your solution for *. tt files and executes them to create other text, again typically source code, files.

What is the purpose of using T4 templates?

We use this template to generate the code when we add a view or controller in MVC. The file extension of this template is tt. Basically when we add a view or controller using a scaffhold template it is called a T4 template. By using this template if we add a controller or view then it generates some code automatically.

What is T4 template in Entity Framework?

T4 templates in entity framework are used to generate C# or VB entity classes from EDMX files. Visual Studio 2013 or 2012 provides two templates- EntityObject Generator and DBContext Generator for creating C# or VB entity classes. The additional templates are also available for download.


1 Answers

Yes, you can. This is how I'm doing it:

string templateText = File.ReadAllText(Host.ResolvePath(templateFileName));
Engine engine = new Engine();
string output = engine.ProcessTemplate(templateText, Host);
//this is optional - record all output to your file of choice:
File.WriteAllText(outputFilePath, output); 
like image 168
veljkoz Avatar answered Oct 21 '22 08:10

veljkoz