Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run EF migrations when deploying to Azure Website via Visual Studio Online

I have an Azure website configured to deploy from Visual Studio Online (hosted TFS). I'm evaluating the move from Database First model to Code First from Existing Database model.

Currently, As I check-in code to Visual Studio Online, it is deployed to Azure website. How to configure this process to run EF Migrations on the remote (live or test) Azure SQL database when I check-in code to Visual Studio Online.

like image 516
Raj Avatar asked Apr 21 '14 06:04

Raj


2 Answers

AFAIK, you need to use the publish profile option to achieve this.

You have to download the publish profile settings file for the website, Import the file in Visual Studio, configure the Execute Code First migrations option and then specify the profile file path in Build Definition used for Continuous deployment.

You can check below post for reference.

http://blogs.msdn.com/b/webdev/archive/2014/04/09/ef-code-first-migrations-deployment-to-an-azure-cloud-service.aspx

like image 159
Jehan33 Avatar answered Oct 18 '22 08:10

Jehan33


I know it is a old post, but I could't find a good answer, so after figure out how to solve it I'm sharing a solution. I work in a project with DDD and N-tiers level. So, it means that the EF isn't in the same project as WebApi, therefore has no option to run migration during the publish wizard. To solve it I have ran update-database directly from package manager console.

Steps:

  1. Acquire the ADO connection string (https://azure.microsoft.com/en-us/documentation/articles/sql-database-connectivity-issues/#connections-to-azure-sql-database)

  2. From package manager console run: Update-database -StartUpProjectName NAMEPROJECTWITHEF -ConnectionString "connection string obtained from item one" -ConnectionProviderName "System.Data.SqlClient"

That's all!

Best Regards, thiago

like image 35
Thiago Avatar answered Oct 18 '22 07:10

Thiago