Add-Migration throwing in .NET Core

While Entity Framework is great (most of the time), in .NET Core there are some pesky issues with it which can cause all sorts of grief when using the package manager console.

Earlier, I wanted to add a migration for one of my projects using the Add-Migration command, which normally works fine, but this time around resulted in a very weird error:

Well, fan-tastic. What's that even supposed to mean?

Now EF comes with a couple of NuGet packages to support the command line stuff, namely:

  • Microsoft.EntityFrameworkCore.Tools
  • Microsoft.EntityFrameworkCore.Design

And a whole bunch of others, most of which I'm not even sure about what they do.

Either way, since the exception is nagging about the design library not being there, I cleared my NuGet cache, re-installed all packages (which is something you generally don't want to do by the way), uninstalled the design package, reinstalled it, but to no avail. It kept giving me that same exception over and over again.

Having spent another hour messing around with packages, making sure the design library was actually present, and everything else you could imagine, I discovered it doesn't have anything to do with the presence of those libraries at all.

While the Package Manager Console allows you to select the project you want to run the commands against, EF's commands ignore this completely. Instead, they rely on the solution's start up project and run the commands against that. Who would've guessed, right?

So the next time any of the EF commands are causing grief, make sure you switch the start up project for your solution to the one you want to run the commands against, and thank me later.

Hopefully they fix this sometime in the future, because it's wildly random, and while I normally don't post fixes to specific issues, I reckon this one will save some people out there a lot of headaches.

Thanks for reading!