How do I run ASP.NET Core Entity Framework migrati

2019-04-11 21:43发布

问题:

I've got a Web API project created using ASP.NET Core 1.1. I use Entity Framework Core Migrations. Locally, that all works well.

However, I'm trying to use Visual Studio team services to automatically run the migrations when I do a release and can't figure out how to do this. Is there some inbuilt component, or should I try to get the dotnet ef tools installed on the agent and run it that way?

回答1:

I would suggest using the dotnet ef tools (during VSTS Build) to generate a .sql script which could be used to generate or update your database wherever needed (during the Release).

dotnet ef migrations script -o migration-script.sql -i -v

During Release amongst other options you could run Invoke-SqlCmd:

Invoke-SqlCmd -inputfile "$inputFile" -serverinstance "$serverInstance" -username "$serverUserName" -password "$serverPassword" -database "$database"