As far as i know the Template file manager replaces all previously generated output files on the .Process() method. So you should call the .Process() method at the very end of your template.
In order to "outsource" the code generating the interface file you could either
use a method inside the same template
foreach(var table in tables) { if (table.name != "sysdiagrams") { manager.StartNewFile(table.name+"mm.cs", ...); // create interface code } manager.StartNewFile(table.name, ...); // create object code } manager.Process();
use a includable template containing a method generating the interface code via the <#@ include #> directive
<#@ include file="interfaces.ttinclude" #> foreach(var table in tables) { if (table.name != "sysdiagrams") Interfacegeneratora(table.Name, manager); // generate object code manager.StartNewFile(table.name, ...); // generate object code here } manager.Process();
Where the file "interfaces.ttinclude" contains something like
<#+ void Interfacegeneratora(string tableName, TemplateFileManager manager) { manager.StartNewFile(tableName + "mm.cs", ...); // generate interface code } #>
process another template manually
foreach(var table in tables) { if (table.name != "sysdiagrams") { var InterfaceT4 = new InterfaceTemplate(); InterfaceT4.Session = new Dictionary<string, object>(); InterfaceT4.Session.Add("tableName", table.name); InterfaceT4.Session.Add("manager", manager); InterfaceT4.InitializeSession(); InterfaceT4.ProcessTemplate(); } manager.StartNewFile(table.Name, ...); // generate object code } manager.Process();
Where you create another T4 template, named "InterfaceTemplate.tt" that is a Preprocessed template. That realizes the same code as the .ttinclude file.
Note: the code is not double checked but shows how it should principally work.
Hope that helps, Nico