dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.51k stars 3.13k forks source link

Clear error messages when scaffolding with customized T4 #31005

Closed AchrWasUnavailable closed 1 year ago

AchrWasUnavailable commented 1 year ago

When there is an error in the T4, the reverse engineering produces a general error message in the output window which makes it hard to find the root cause. Would it be possible to produce clear error messages like the output of a tt file > Run custom tool?

E.g. output reverse engineer: `System.InvalidOperationException: Reverse engineer error: Microsoft.EntityFrameworkCore.Design.OperationException: Processing 'C:\Development\Playground\OEFS.Test\OEFS.Test.Data\OEFS.Test.Data\CodeTemplates\EFCore\DbContext.t4' failed. at void Microsoft.EntityFrameworkCore.Scaffolding.Internal.TextTemplatingModelGenerator.HandleErrors(TextTemplatingEngineHost host) at ScaffoldedModel Microsoft.EntityFrameworkCore.Scaffolding.Internal.TextTemplatingModelGenerator.GenerateModel(IModel model, ModelCodeGenerationOptions options) at ScaffoldedModel RevEng.Core.ReverseEngineerScaffolder.ScaffoldModel(string connectionString, DatabaseModelFactoryOptions databaseOptions, ModelReverseEngineerOptions modelOptions, ModelCodeGenerationOptions codeOptions, bool removeNullableBoolDefaults, bool dbContextOnly, bool entitiesOnly, bool useSchemaFolders) in C:/projects/efcorepowertools/src/GUI/RevEng.Core/ReverseEngineerScaffolder.cs:line 375 at SavedModelFiles RevEng.Core.ReverseEngineerScaffolder.GenerateDbContext(ReverseEngineerCommandOptions options, List schemas, string outputContextDir, string modelNamespace, string contextNamespace, string projectPath, string outputPath) in C:/projects/efcorepowertools/src/GUI/RevEng.Core/ReverseEngineerScaffolder.cs:line 102 at ReverseEngineerResult RevEng.Core.ReverseEngineerRunner.GenerateFiles(ReverseEngineerCommandOptions options) in C:/projects/efcorepowertools/src/GUI/RevEng.Core/ReverseEngineerRunner.cs:line 88 at async Task EfReveng.Program.Main(string[] args) in C:/projects/efcorepowertools/src/GUI/efreveng/Program.cs:line 81

at ReverseEngineerResult EFCorePowerTools.Handlers.ReverseEngineer.ResultDeserializer.BuildResult(string output) at async Task EFCorePowerTools.Handlers.ReverseEngineer.EfRevEngLauncher.GetOutputAsync() at async Task EFCorePowerTools.Handlers.ReverseEngineer.EfRevEngLauncher.LaunchExternalRunnerAsync(ReverseEngineerOptions options, CodeGenerationMode codeGenerationMode, Project project) at async Task EFCorePowerTools.Handlers.ReverseEngineer.ReverseEngineerHandler.GenerateFilesAsync(Project project, ReverseEngineerOptions options, string missingProviderPackage, bool onlyGenerate, List packages, string referenceRenamingPath) at async Task EFCorePowerTools.Handlers.ReverseEngineer.ReverseEngineerHandler.ReverseEngineerCodeFirstAsync(Project project, string optionsPath, bool onlyGenerate, bool fromSqlProj)`

E.g. output tt file > Run custom tool: image

ajcvickers commented 1 year ago

/cc @bricelam

bricelam commented 1 year ago

@AchrWasUnavailable How are you running the tool? Errors and warnings from the T4 file should be reported on the console:

image

AchrWasUnavailable commented 1 year ago

@bricelam I am using EF Core Power Tools in VS2022 which uses the EFCore T4 templates and Microsoft.EntityFrameworkCore.Scaffolding to generate the models and redirects any exceptions to the VS output window.

ErikEJ commented 1 year ago

There is a potential that Power Tools does not pass on all the errors

ErikEJ commented 1 year ago

@AchrWasUnavailable This has been fixed in the latest daily build of EF Core Power Tools

AchrWasUnavailable commented 1 year ago

@ErikEJ Very much appreciated! Thnx!