让Migrate.exe工作

Kar*_*ran 12 migration asp.net-mvc entity-framework-4

我一直在努力执行EF Migrate.exe.

我的解决方案有几个项目.迁移和实体存在于项目数据中.控制器和视图存在于Web中.

我尝试使用migrate.exe - 但是我正在努力让第一个参数(程序集)被接受.文件说:

程序集:指定包含迁移配置类型的程序集的名称.

我试过了:

migrate.exe"MySolution\DataProject\bin\Debug\Data.dll"

ERROR: Could not load file or assembly 'D:\\MySolution\\Data\\bin\\Debug\\Data' or one of its dep
endencies. The given assembly name or codebase was invalid. (Exception from HRES
ULT: 0x80131047)
Run Code Online (Sandbox Code Playgroud)

什么出了什么问题?

Zas*_*asz 33

看完这个,这个,这个

我(我认为)你需要什么:

  1. 如果对.NET 4程序集使用migrate.exe,则需要将packages\EntityFramework.5.0.0\tools中的Redirect.config重命名为migrate.exe.config,并将其作为migrate.exe复制到SAME目录.要对.NET 4.5程序集运行migrate.exe,您不需要此副本,migrate.exe.config必须不存在.
  2. 正确版本的实体框架DLL必须作为migrate.exe位于SAME目录中.正确的版本是packages\EntityFramework.5.0.0\lib \net40 \,用于针对.NET 4程序集运行migrate.exe.正确的版本是packages\EntityFramework.5.0.0\lib \net45 \,用于针对.NET 4.5程序集运行migrate.exe
  3. 如果指定/ StartUpDirectory =不指定/ assembly示例的路径:C:\Tools\migrate.exe some.dll /StartUpDirectory=C:\Project\bin\.
  4. 如果您没有指定启动目录,那么您需要在/ assembly示例中指定完整路径:C:\Tools\migrate.exe C:\Project\bin\some.dll- 在这种情况下,migrate.exe将无法加载some.dll的依赖项,除非您放置所有some.dll的依赖项并将其作为migrate.exe放在SAME目录中.
  5. 如果您将migrate.exe放在与some.dll相同的路径中,那么migrate.exe将能够使用您的应用程序使用的相同EntityFramework.dll,并且可以加载所有依赖项,并且可以加载some.dll而不用任何路径都喜欢 C:\Tools\migrate.exe some.dll
  6. 如果你将migrate.exe放在一个单独的工具文件夹中,比如我在SAME目录中需要正确版本的EntityFramework.dll作为migrate.exe,它将需要该/StartUpDirectory=<the path where you target dll is present>子句,你应该指定程序集的名称路径如:C:\Tools\migrate.exe some.dll /StartUpDirectory=C:\Project\bin\
  7. 继承人我使用的powershell命令:
$SolutionPath = (Resolve-Path '..').Path
$ToolsPath = "$SolutionPath\Build\Lib\"

task db  { 
  $migrator = $ToolsPath + 'Migrations\migrate.exe'  
  $migrateCommand = "$migrator zasz_me.dll /StartUpDirectory=$SolutionPath\zasz.me\bin\ /connectionStringName:FullContext /startUpConfigurationFile:$SolutionPath\zasz.me\Web.config /verbose"
  Write-Host $migrateCommand
  Invoke-Expression $migrateCommand
}
Run Code Online (Sandbox Code Playgroud)