我一直在努力执行 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)
知道出了什么问题吗?
看完之后this, this, and this
我有(我认为)你需要的东西:
- 如果您对 .NET 4 程序集使用 migrate.exe,则需要将 packages\EntityFramework.5.0.0\tools 中提供的 Redirect.config 重命名为 migrate.exe.config,并将其复制到与 migrate.exe 相同的目录。要针对 .NET 4.5 程序集运行 migrate.exe,您不需要此副本,migrate.exe.config 不得存在。
- 实体框架 DLL 的正确版本必须与 migrate.exe 位于同一目录中。正确的版本是packages\EntityFramework.5.0.0\lib\net40\,用于针对.NET 4程序集运行migrate.exe。正确的版本是packages\EntityFramework.5.0.0\lib\net45\,用于针对 .NET 4.5 程序集运行 migrate.exe
- 如果指定 /StartUpDirectory= 则不要指定 / assembly 示例的路径:
C:\Tools\migrate.exe some.dll /StartUpDirectory=C:\Project\bin\
.
- 如果不指定启动目录,则需要在 / assembly 示例中指定完整路径:
C:\Tools\migrate.exe C:\Project\bin\some.dll
- 在这种情况下,migrate.exe 将无法加载 some.dll 的依赖项,除非您将所有 some.dll 的依赖项放在与 migrate.exe 相同的目录中。
- 如果您将 migrate.exe 放在与 some.dll 相同的路径中,那么 migrate.exe 将能够使用您的应用程序使用的相同 EntityFramework.dll,并且可以加载所有依赖项,并且可以加载 some.dll 而无需任何路径像
C:\Tools\migrate.exe some.dll
- 如果您将 migrate.exe 放在单独的工具文件夹中,就像我所做的那样,它需要将 EntityFramework.dll 的正确版本放在与 migrate.exe 相同的目录中,它将需要
/StartUpDirectory=<the path where you target dll is present>
子句,并且您应该指定不带路径的程序集名称,例如:C:\Tools\migrate.exe some.dll /StartUpDirectory=C:\Project\bin\
- 这是我使用的 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
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)