2

I'm trying to set up our project to re-scaffold the DbContext and all the models before each build in order to catch any database changes within our API. However when I set up the pre-build command and run/build the project, it just spawns a bunch of .NET Host tasks to take up the rest of my CPU and the build stalls forever. So then I have to open task manager and kill Visual Studio 2019.

I'm using VS 2019. This is a .Net Core 3 API with EF Core. Here's an example of the command that I placed in the pre-build. It runs fine in PMC.

dotnet ef dbcontext scaffold "Server=localhost\SQLEXPRESS;Database=master;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer --output-dir Models --force --context-dir Data --context APIContext

How do I get this to work as a pre-build event?

Joe Higley
  • 1,762
  • 3
  • 20
  • 33
  • That is not a good approach, why not include the database schema in source control instead? – ErikEJ Nov 05 '20 at 06:37
  • 1
    @ErikEJ Why is it not a good approach. And what would including the schema in source control do for me? – Joe Higley Nov 05 '20 at 17:37
  • That changes code-first into database-first, well, OK. My main objection would be that this adds a very expensive build step that's not necessary 99% of the times. Also, it's hard to do this in collaboration projects where everybody works in branches. Even if possible I'd never ever do it myself, but, admittedly, academically it's interesting. – Gert Arnold May 06 '21 at 12:47
  • 1
    You know that these commands internally run build, right? So apparently putting them into pre/post build events is not a good idea as it causes the equivalent of stack overflow. – Ivan Stoev May 07 '21 at 20:41

0 Answers0