I’m trying to create a T4 template which inherits from another one that is in a separate assembly.
The problem is that the T4 template in the referenced assembly is not generated if I use the TextTemplatingFileGenerator custom tool (also with the visibility property of the template directive set to true), but only if I use the TextTemplatingFilePreprocessor custom tool.
Am I using it the wrong way? Should I use a different technique instead (include, or something like suggested here)?
UPDATE
A few details about the scenario as requested in comments:
In my company, we need a reusable framework to generate converters/mappers between objects (usually database entities to DTOs and vice versa).
We’re tired of frameworks that hide what they do internally and usually result in runtime exceptions, especially with collections.
I would like to define a template to be reused in data mapping projects where we take definitions of objects from another assemblies via reflection and we generate static classes with mapping extension methods.
Thanks
Francesco
If you want to use the template both as a standalone template in the first assembly and inherit from it in the second, then you’re best to create two templates in the first assembly.
For the first template, use TextTemplatingFileGenerator and include the actual template text.
For the second template, use TextTemplatingFilePreprocessor and have the content just be a single <#@ include #> directive to include the first template file.