1

When I release my Asp.Net MVC app to azure web app using VSTS and a Hosted VS2017 agent, the EF Migration (to Azure SQL) doesn't execute on application start the same way it can be done publishing from Visual Studio with the option "Execute Code First Migrations (Runs on application start)".

What would be the specific steps on VSTS to make EF migration run and update the database the same way as when publishing from VS ?

donquijote
  • 1,642
  • 5
  • 19
  • 41
  • 1
    You can use the `migrate.exe` tool. [This article](https://geeks.ms/lfraile/2016/10/29/im-back-executing-entity-framework-migrations-from-vsts-release-management/) explains in detail how to do it with the specific build and release steps. Note that the migrations here are not run on application start, but before deploying the applications. – Diana Jul 06 '17 at 20:20
  • 1
    Try to create a publish profile through VS with Migration configured, then publish web app to a package by using Visual Studio Build task with /p:DeployOnBuild=true /p:PublishProfile=CustomProfile;DesktopBuildPackageLocation=‌​"$(build.artifactsta‌​gingdirectory)\WebAp‌​pCore.zip" argument, after that deploy this package to azure app – starian chen-MSFT Jul 07 '17 at 07:27
  • The approach by @starain-MSFT worked. Appreciated! – donquijote Jul 11 '17 at 22:12
  • My steps are simple, could you provide the detail steps to do it, you can post an answer and accept it as answer. (My dbo._MigrationHistory is empty after deploying app to azure web app, do you know the reason? I am using azure SQL Server) – starian chen-MSFT Jul 12 '17 at 01:34
  • @starain-MSFT, I also use Azure SQL and my _MigrationHistory didn't empty, i.e. it added the new migration after the release from VSTS. I will write the detailed steps i followed as answer. – donquijote Jul 12 '17 at 01:44
  • I will follow up your steps to do it. – starian chen-MSFT Jul 12 '17 at 02:34
  • BTW, do you use web core project or general MVC app (e.g. MVC 4)? I am using web core project in VS 2017. – starian chen-MSFT Jul 12 '17 at 05:23
  • I am using VS 2017 but the app is Asp.Net MVC, not core yet. The web app also has webjobs and I had to make publish profile available to the web jobs one by one for the build process to succeed. – donquijote Jul 12 '17 at 14:50
  • I have the issue with core web app, you may try it with .net core app if you have time. – starian chen-MSFT Jul 13 '17 at 02:10

1 Answers1

0

Is possible to have VSTS use the same Publish Profile as in VS which in my case is a Web Deploy process to Azure Web App and includes the option to run migrations on application start.

In the VSTS build definition, Variables tab, add the following entries:

DeployOnBuild: true

PublishProfile: NameOfTheVSPublishProfileFile

DesktopBuildPackageLocation: $(System.DefaultWorkingDirectory)/MyBuildFolderName/drop/MyProjectZipName.zip

Then Build and Release.

Next time you run the app the new migrations will execute in the same way as when publishing from VS.

donquijote
  • 1,642
  • 5
  • 19
  • 41