Some men want to watch the build fail

How to resolve persistent “Build started… Build failed.” when trying to run Entity Framework Core commands?

This post was most recently updated on April 15th, 2024.

3 min read.

This time, I’m happy to present you perhaps the simplest way of fixing an annoying and persistent issue with a misleading error message! Wait, does that sound familiar? It’s almost like that’s what half of my articles are about…

Anyway, I was happily going my way about creating a couple of new fields to an entity and then scaffolding my changes to a new migration using Entity Framework Core’s Add-Migration, but this happened:

Build started...
Build failed.

“Oh”, I thought. “I must have messed something up and the build is broken.”

Well, I hit Ctrl+Shift+B, and build passed just fine.

Wait, what now?

AI-powered summary: Quick Fix for Entity Framework Core Build Errors

  1. Encounter a ‘Build started… Build failed’ error with Entity Framework Core commands? The issue often lies not with your main project but with another project in the solution that may be broken. Ensure all projects build correctly to run EF Core commandlets successfully. Solutions include:
  • Checking the build status of all projects
  • Resolving any build issues in auxiliary projects
  • Re-running EF Core commands after fixes

Problem

My project was building, debugging, rebuilding etc. just fine, but failed to run Add-Migration, or Remove-Migration (or Update-Database for that matter)!

What in tarnation

Below is what it looked like in the Package Manager Console:

"Build started", "Build failed" in Entity Framework's Add-Migration
“Build started”, “Build failed” in Entity Framework’s Add-Migration

As you can see, specifying -Verbose make any difference. My normal first go-to, making sure the Default project is the correct one, selecting the right startup project in Visual Studio’s Solution Explorer, and even specifying -Context and -Project made no change whatsoever.

In addition to running into this with the CommandLets (Add-Migration and such), you will run into the same issue if you try to use any dotnet ef migrations commands, like:

dotnet ef migrations add InitialMigration
dotnet ef migrations remove
dotnet ef database update

So, what gives?

Solution

Okay, so once again, this is going to be a bit stupid! But that’s the way I like to bang my head on the keyboard, so let’s get to it.

Time needed: 5 minutes

How to fix “Build started… Build failed.” when running EF Core commands?

  1. Verify your projects build successfully

    Literally – go through each of the projects in your solution and make sure they can be built.

  2. Option 1: Fix your projects

    If you find a project that fails to build, most of the time you’ll want to fix it. There could be a lot of reasons why your build fails, so I won’t be able to cover them here.

    But if you can’t, or don’t want to fix a project (one that’s not actually required to run your project), you might want to take a look at Option 2 below…

  3. Option 2: Unload your projects if you don’t want to fix it

    If your unbuildable project isn’t that important (at least in the moment), just unload it.

    Unload a project in Visual Studio Solution Explorer

For me, it was another project that was just a bit broken and wouldn’t build – that caused me no issues with my normal development workflow (it was a tooling project only occasionally used, and somehow, somewhere along the line, someone broke it), but Entity Framework Core commandlets require all of the projects to be kosher in order to run successfully.

So, that solved it for me. Let me know whether it helped you or not! :)

References

A couple of links I’ve found useful:

mm
4.8 6 votes
Article Rating
Subscribe
Notify of
guest

10 Comments
most voted
newest oldest
Inline Feedbacks
View all comments