Reusing Generators/Templates from different assemblies

Jun 19, 2013 at 8:01 PM
I would like to define a Generator class in one project and be able to call it from another project (without including the file containing it as a .ttinclude). So I want to define MyGenerator in MyGenerator.dll. Then in, which exists in MyGeneratorConsumer.csproj, I want to call MyGenerator. MyGeneratorConsumer will have a DLL dependency on MyGenerator.dll (so the source for MyGenerator.csproj will not be available).

I tried defining MyGenerator in a regular .cs file in MyGenerator.csproj, but when I try to call it from another project, I get a cast exception somewhere in the T4Toolbox code.

Is there a way to do this?
Jun 19, 2013 at 8:06 PM
Edited Jun 19, 2013 at 8:07 PM
This is something that Preprocessed Templates are good for. Oleg is working on adding support for Preprocessed templates to the VS2012 version of the T4Toolbox.
Jun 19, 2013 at 8:41 PM
Thanks. Are Preprocessed Templates synonymous with Runtime Text Templates? I'm already using them quite a bit (they're easier to unit test), but at the end of the day I need the T4Toolbox's ability to control the file that gets outputted to.

For now, I'm pulling as much logic as possible out of my Generator class and putting that logic in the shared DLL. Then I duplicate the shell of the Generator anywhere I'm consuming it. Not ideal, but it works, I suppose.