Open gao-artur opened 1 year ago
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
<#@ include file="C:\local\CodeTemplates\EFCore\DbContext.t4" #>
Or, with relative paths:
<#@ include file="..\..\..\..\..\CodeTemplates\EFCore\DbContext.t4" #>
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?