I have set up continuous integration for my project with Visual Studio Online
build definitions.
When it comes to deploying my database (to an Azure test environment) I just build my SQL Server Database Project
with the right publishing settings.
But I want to switch to Entity Framework
's code first approach and leverage the migration feature, which requires me to call migrate.exe.
My question is - how could I run migrate.exe from VSO
build definitions?
You can also look at executing your migrations at App startup time.
add the following to your Application_Start() event in global.asax
This will fire the migrations at each application startup. you could also wrap with conditional logic to control how it is fired.
We've succesfully implemented an automated EF code first migration at deploy time on top of TFS Build vNext in the following way:
It basically involves 3 steps (per EF-context):
In detail:
The MigrateEFContext.bat file assembles the migrate.exe-command with its arguments:
I assume you are using vNext build, add a "Nuget Installer" task in your build definition first to restore the Entity Framework during the build. Migrate.exe will be installed in \packages\EntityFramework.\tools folder. Then add a "Command Line" task to run the migrate.exe. Enter “\packages\EntityFramework.\tools\migrate.exe" in "Tool" area and the arguments in "Arguments" field.