Today released V1.9.64 of tangible T4 Editor for VS2010 – PRO EDITION which now allows you to also transform specific T4 templates in your project on build. Here is a short walktrough that shows that this feature also supports templates that access EnvDTE e.g. to create multiple output files.
Let’s try the basics
1. I have installed tangible T4 Editor PRO EDITION
2. I created a C# project and added a Hello World.tt file to the project with the following content
3. Now I can set this simple template to transform on build – so each time the project is build it is run:
4. Let’s hit “Build” and see what is reported in the output window:
Now let’s do multiple output files within this auto-transform process
3. Create a second file TempalteFileManager.ttinclude. Then right click the Editor to open the Conext menu and select “Insert Code from Gallery”.
Then press the button “Search online templates” to find it. then insert its contents from the gallery.
4. Now go back to HelloWorld.tt and change its contents to
for (int i=1;i<3;i++){fm.StartNewFile("Class" + i + ".cs");
this.Write(System.DateTime.Now.ToString());}fm.Process(true); #>
5. And run it … cool i finally got this nice multiple output thing and transform on build running
Even more advanced: Generate into subdirectories and other projects:
var manager = TemplateFileManager.Create(this);
manager.CanOverrideExistingFile = false;
manager.StartNewFile("Class1.cs");
this.WriteLine("// Class is assigned to template ");
manager.StartNewFile("Class2.cs", folderName:"CodeFolder");
this.WriteLine("// Class is created in subfolder ");
manager.StartNewFile("Class3.cs", projectName:"ClassLibrary");
this.WriteLine("// Class is generated in Project ClassLibrary");
foreach (string item in fileNames) {
manager.StartNewFile(item, projectName:"ClassLibrary", folderName:"SubFolder");
this.WriteLine("// Classes are created in Project ClassLibrary/SubFolder ");
}
manager.Process();
Many thanks to Björn Borgsdorf and Rene Leupold who made this thing possible!
Happy Birthday Björn!
1 comment:
Folders do not work on VS2012, possible because of changes to DTE?
Post a Comment