-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document how to share T4 templates across projects #4292
Comments
Linked files? |
Tried it. But template files should be physically located in the destination folder. |
@gao-artur You can reference a shared copy of the template file from within the template file of each project. For example, the contents of "MyProject\CodeTemplates\EFCore\DbContext.t4" would be
Or, with relative paths:
And then "C:\local\CodeTemplates\EFCore\DbContext.t4" is the actual T4 template that you want to use in multiple places. Likewise for "EntityType.t4". |
@ajcvickers, thank you! It worked! |
Before EF Core 7, we used to override the
ICSharpDbContextGenerator
implementation in theIDesignTimeServices
to customize theDbContext
generation during the scaffold. Starting EF Core 7, this approach no longer works, and we are now exploring the t4 templates approach.We have many (~15) DB to scaffold. Their models will be located in different folders, but they all need the same template. We have a single
Scaffold.Console
app, where we implemented our customizations, and it uses as a startup project during the scaffold. Unfortunately, putting the templates in the startup project folder doesn't work. It works only when templates are located in the destination folder (the folder where we write the generated files).I have seen this issue, which was closed as
Won't do
. Any suggestion on how to reuse the same template without copying it 15 times and synchronizing the changes on every update?The text was updated successfully, but these errors were encountered: