Running update-database from Team City

僤鯓⒐⒋嵵緔 提交于 2019-12-03 05:51:15

问题


I have created a new application using Entity Framework 4.3 database migrations. The migrations work great from the package manager console using the "update-database" command.

Now I want to run the database migrations every time the application is built using Team City, it looks like I need to create a powershell script that will do this.

Can anyone point me to some instructions on how to get the package manager commands to run from the command line, or powershell? All I can find is instructions on how to do this via the package manager console, which I don't know how to run from a Team City build step.


回答1:


migrate.exe is what I was looking for, it is found in "packages\EntityFramework.4.3.1\tools".

Add a new build step in Team City using:

Runner type: command line

Command executable: packages\EntityFramework.4.3.1\tools\migrate.exe

Command parameters: MyApplicationName /StartupDirectory:MyApplicationName\bin




回答2:


Install Entity Framework nuget to the repo and use the accompanying migrate.exe under packages\EntityFramework.5.0.0\tools\ or equivalent.

Then run a batch script like this:

SET AssemblyName=MyMvc4App
SET StartUpDirectory=MyMvc4App\bin\
SET ConnectionString=Server=tcp:XXXX.database.windows.net,1433;Database=XXXX;User ID=XXXX;Password=XXXX;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;MultipleActiveResultSets=True
SET ConnectionStringProvider=System.Data.SqlClient
SET ConfigFilePath=%CD%\MyMvc4App\web.config
SET MigrateExe=packages\EntityFramework.5.0.0\tools\migrate.exe

%MigrateExe% %AssemblyName%.dll /startUpDirectory:%StartUpDirectory% /startUpConfigurationFile:"%ConfigFilePath%" /connectionProviderName:"%ConnectionStringProvider%" /connectionString:"%ConnectionString%" /verbose
pause

I answered a similar question and there I explain why I have yet to get it working without specifying a web/app.config file.



来源:https://stackoverflow.com/questions/9868252/running-update-database-from-team-city

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!