Nei*_*eil 5 build-automation entity-framework ef-migrations entity-framework-5
我将所有的ef代码首次迁移到一个名为的单独程序集中 Migrations
从包管理器控制台中我输入Add-Migration xyz了一个支持迁移
是否有可能从视觉工作室外面做到这一点?我正在使用rake脚本为我的构建做很多自动化,但这是我还没有完成的一部分.这里的目标是做到以下几点
rake db:add_migration "xyz"
这将运行一些命令并将迁移添加到指定的项目.这是我唯一无法弄清楚如何实现自动化的方法!我可能会构建其他任务,例如删除和创建数据库以及迁移到脚本,以便它可以在我的roundhouse迁移下运行.
相关材料
Add-Migration [-Name] <String> [-Force]
[-ProjectName <String>] [-StartUpProjectName <String>]
[-ConfigurationTypeName <String>] [-ConnectionStringName <String>]
[-IgnoreChanges] [<CommonParameters>]
Run Code Online (Sandbox Code Playgroud)
我可以看到EF从nuget安装到packages文件夹
packages\EntityFramework.5.0.0\tools
Run Code Online (Sandbox Code Playgroud)
我可以在文件中看到 EntityFramework.psm1
function Add-Migration
{
[CmdletBinding(DefaultParameterSetName = 'ConnectionStringName')]
param (
[parameter(Position = 0,
....
}
Run Code Online (Sandbox Code Playgroud)
但我不确定如何从命令行执行它.我试过了
..\packages\EntityFramework.5.0.0\tools>powershell EntityFramework.psm1 Add-Migration
Run Code Online (Sandbox Code Playgroud)
但这会导致错误
The term 'EntityFramework.psm1' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name,
or if a path was included, verify that the path is correct and try again.
At line:1 char:21
+ EntityFramework.psm1 <<<< Add-Migration
+ CategoryInfo : ObjectNotFound: (EntityFramework.psm1:String) [],
CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Run Code Online (Sandbox Code Playgroud)
查看EntityFramework.psm1它只是EntityFramework.PowerShell.dll的脚本外观.实际的添加迁移功能System.Data.Entity.Migrations.AddMigrationCommand在该程序集的类中实现.
查看源代码,它通过以下行获取当前活动的项目(我假设这是在powershell控制台中选择的项目):
get { return (Project)_domain.GetData("project"); }
Run Code Online (Sandbox Code Playgroud)
Project是EnvDTE.Project(如果我正确谷歌)是一种与IDE接口的方式.进一步的源读取显示文件通过与IDE连接添加到项目中.
对我来说,看起来脚手架代码与Visual Studio集成太多,无法作为命令行构建的一部分在Visual Studio外部运行.
我回到这里,并发现它可能是可能的.还有另一个SO问题描述了如何在visual studio之外使用EnvDTE,例如从命令行应用程序:
因此,EntityFramework.PowerShell.dll在调用AddMigrationCommand类之前,如果app域准备好了正确的EnvDTE对象,那么确实可以编写一个自己的.exe包装器.要做到这一点,你必须分析实体框架源代码,以了解如何欺骗脚手架代码以便在Visual Studio中运行它.
所以,最后:它可能是可能的 - 但是为它编写自己的工具将是一个非常简单的项目.
| 归档时间: |
|
| 查看次数: |
3316 次 |
| 最近记录: |