This post describes how to enable EF Code First migrations on TeamCity or any other continuous integration server or deploy script.
Lets assume you have MyData class library with your migrations and DbContext. This class library references Entity Framework and has MyData.config with connection string.
If you use NuGet (if not, you really should try it), then migration tool migrate.exe is under packages\EntityFramework.5.0.0\tools\ directory.
First, let's add migrate.cmd file to MyData project
Be careful when creating file with visual studio, you have to save the file in ASCII encoding or utf-8 without signature, otherwise it will have BOM bytes at the beginning (hex EF BB BF) and command line will fail to run.
Now we make migrate.cmd copy to output directory every build.
In migrate.cmd we will write small script to copy migration tool and run migrations. We have to copy migrate.exe to our bin folder because it needs EntityFramework.dll
copy /Y ..\..\..\packages\EntityFramework.5.0.0\tools\migrate.exe .
migrate.exe MyData /startupConfigurationFile:MyData.dll.config
Finally, we make migrate.cmd to run as a build step in TeamCity
If you have different configuration types in one class library, you have to specify their names like this:
migrate.exe MyData MyConfiguration1 /startupConfigurationFile:MyData.dll.config migrate.exe MyData MyConfiguration2 /startupConfigurationFile:MyData.dll.config