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?
Open the Package Manager Console from Tools → Library Package Manager → Package Manager Console and then run the enable-migrations command (make sure that the default project is the project where your context class is).
From the Tools menu, select NuGet Package Manager > Package Manager Console. The enable-migrations command creates a Migrations folder in the ContosoUniversity project, and it puts in that folder a Configuration. cs file that you can edit to configure Migrations.
The ef6.exe command line tool is found in the tools/ subfolder of the EntityFramework NuGet package.
Open the Package Manager Console. Select Tools > NuGet Package Manager > Package Manager Console. The Enable-Migration command creates the Migrations folder, which contains a script to initialize the database. Open the Configuration.
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:
SET EFDir=%1
SET EFContext=%2
SET connStringDataSource=%3
SET connStringInitialCatalog=%4
SET connectionProviderName=%5
%EFDIR%\migrate.exe %EFContext% /ConnectionString:"Data Source=%connStringDataSource%;Initial Catalog=%connStringInitialCatalog%;Integrated Security=true" /connectionProviderName:%connectionProviderName% /verbose
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With