我遵循了这个关于如何使用自定义 T4 模板从带有 EF Core 的数据库生成代码的文档: https://learn.microsoft.com/en-us/ef/core/managing-schemas/scaffolding/templates
现在,我正在修改模板,调试T4文件中错误的最佳方法是什么?
如果我执行脚手架命令并且T4文档中有any错误,我只会得到一个非常通用的错误消息:
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.TextTemplatingModelGenerator.GenerateModel(IModel model, ModelCodeGenerationOptions options)
这是我在 Visual Studio 包管理器控制台中使用的脚手架命令:
Scaffold-DbContext "Data Source=..." Microsoft.EntityFrameworkCore.SqlServer -UseDatabaseNames -Context SqlServerContext -StartupProject <...> -ContextDir Context -OutputDir Model -Tables <...>