Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure T4 template to generate classes in different project

I'm using new Entity Framework 4.1 Model first approach that makes use of T4 templates to generate classes from visual model.

Can I configure that T4 templates to create POCO classes and Context classes (or at generally whatever they generate) in another project?

Please note that I don't want to move T4 template (file with .tt) to another project and then just change the template to EDMX file in persistence project. I want it to really generate that classes in another project then the location of template. Is that possible ?

Thank you for answers


Notes: this is no duplicate of question Generate POCO classes in different project to the project with Entity Framework model as author there wanted just what I don't: move the whole template together with classes generated.

I fully understand that moving the whole template will not mean that the other project will become persistence aware. Still, I have my reasons why I don't want it in the same project with POCO classes.

like image 449
Rasto Avatar asked Mar 24 '11 16:03

Rasto


1 Answers

Multiple projects sharing the same templates

Whenever I use shared T4 templates I:

  1. create a solution folder
  2. put my generation T4 template in it and set its extension to ttinclude
  3. add additional T4 templates to my projects wherever needed but with tt extension
  4. depending on template functionality, they may only have to reference the shared ttinclude template as in this example of mine that I use to generate enum types of database lookup tables;

If you're using provided templates you will have to modify them a bit to make this work, because they will have to reference EDMX file on a different location than default. You can as well provide this path as a local variable that you override in your per-project template so it will use the overridden path instead of default defined in the ttinclude file.

like image 186
Robert Koritnik Avatar answered Oct 04 '22 14:10

Robert Koritnik