IT:AD:Transformations:T4:HowTo:Create a Multi Target Transformation
Just because the default behaviour is to transform a .tt to one ouput file, it doesn't mean you can't produce *n files from one single transformation.
<#@ template language="C#" debug="false" hostspecific="true"#>
<#@ include file="EF.Utility.CS.ttinclude"#>
<#@ include file="Manager.ttinclude"#>
<#@ output extension=".xx"#>
<#
EntityFrameworkTemplateFileManager fileManager = EntityFrameworkTemplateFileManager.Create(this);
#>
<#
for (int i=0;i<3;i++)
{
fileManager.StartNewFile(string.Format("Example{0}.xx",i));
#>
<#=string.Format("Example{0}.xx",i)#>
<#
fileManager.EndBlock();
}
#>
<#
//You must call the Process method at the end:
fileManager.Process(true);
#>
The output of the above will be:
- My.tt
- Example0.xx
- Example1.xx
- Example2.xx
- My.xx
Note that this is a bit of an abusse of the EntityFrameworkTemplateFileManager which was never intended for this. But it works. If you want to be a bit of a purist you can always go and download (actually cut/paste) the ttinclude found here and install it into C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes
## Resources ##