This post was most recently updated on April 27th, 2023.2 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?
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:
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?
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?
- Verify your projects build successfully
Literally – go through each of the projects in your solution and make sure they can be built.
- 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…
- 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.
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! :)
A couple of links I’ve found useful:
- Documentation for dotnet ef core commands
- Documentation for dotnet ef core PowerShell commandlets:
- How to fix OnePlus 10 Pro Bluetooth issues - May 23, 2023
- How to actually uninstall conflicting PowerShell modules? - May 16, 2023
- How to enable Developer Mode on Android? - May 9, 2023