How to run Code-First Migrations from a psake buil

2019-02-07 07:34发布

I can type Update-Database, Enable-Migrations etc, from Package Manager Console and it works fine.

If I need to do the same from a regular powershell session, or in a psake build file, then how do I do it?

I tried importing the module EntityFramework.5.0.0\tools\EntityFramework.psm1 from the packages directory, and I did get the Update-Database, Enable-Migrations functions, but I cannot supply their arguments - they need a project, source, and 6 more - and there is no documentation whatsoever. Can I not automate the database deploy on some machine in our CI chain ?

2条回答
Juvenile、少年°
2楼-- · 2019-02-07 08:01

The problem with importing the module into a PowerShell console is that I believe the module expects to run in a context where it has a Visual Studio DTE object available. That environment is the NuGet Package Manager Console. This issue has been brought up before. Check out this blog post and this SO question.

This blog post shows how to write code that does migrations.

查看更多
家丑人穷心不美
3楼-- · 2019-02-07 08:09

Use migrate.exe from EntityFramework NuGet package.

https://stackoverflow.com/a/14139229/991267

查看更多
登录 后发表回答