Interestingly enough, exactly the same code was working fine when the project type of the library was "Class Library (.NET Standard)" instead of "Class Library (.NET Core)".
After many experiments I figured out a way to make it work. It seems that it needs an "application" to be present in the solution for the migrations to work - could be web or console.
So, to fix this issue:
- Add "Console App (.NET Core)" to your solution
- Add EF Core nuget packages to the console app
- Reference your class library from the console app
- COMPILE!!
- Done - now you can generate migrations (don't forget to set your console app as a "StartupProject" either through parameter or in the PMC combo at the top)