Can't run EF migration where DbContext connection string is set at runtime and separate project from application
Okay, so after much looking, you can't do this by default. No tooling for class libraries since January at all, which seems horrible to me. And no tooling as the link I posted mentions for a .NET CORE class library targeted at 461 using EF6, because EF6 tools do not recognize project.json dependency format.
However, blessed be, a gentleman by the name of Mohammad Rahhal created such a library to accomplish this: https://github.com/mrahhal/Migrator.EF6/blob/master/README.md
And using the information described in this issue: https://github.com/mrahhal/Migrator.EF6/issues/9
I was able to successfully run a migration, it does require some hacky stuff, but it works for the time being, better than other alternatives provided elsewhere.
1) Download this nuget package for Migrator.EF6.Tools nuget.
2) Change project.json to include:
{
"version": "1.0.0-*",
"dependencies": {
"EntityFramework": "6.1.3",
"Migrator.EF6.Tools": "1.0.5"
},
"frameworks": {
"net461": {}
},
"buildOptions": {
"emitEntryPoint": true
},
"tools": {
"Migrator.EF6.Tools": {
"imports": "portable-net45+win8+dnxcore50",
"version": "1.0.5"
}
}
}
3) Add a program.cs file with Main stub to the class library project:
public class Program
{
public static void Main(string[] args)
{
}
}
You are now set to run migrations from VS2015 Dev Command Prompt. Navigate to the project directory, and run the migration commands described in the readme linked above.
However, it should be noted, once you are done running migrations, set emitEntryPoint
value to false again so it can still be treated like a normal class library. Basically you are tricking the EF tooling to think your class library is a console app, but you don't want it to be treated like that for deployment.