Run EF migration on VSTS release

2019-03-02 10:09发布

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 ?

1条回答
何必那么认真
2楼-- · 2019-03-02 10:22

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.

查看更多
登录 后发表回答