How to run Code-First Migrations from a psake build?

半腔热情 提交于 2019-11-30 14:14:24

问题


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 ?


回答1:


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.




回答2:


Use migrate.exe from EntityFramework NuGet package.

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



来源:https://stackoverflow.com/questions/12238640/how-to-run-code-first-migrations-from-a-psake-build

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