获取Migrate.exe工作 [英] Getting Migrate.exe to work

查看:412
本文介绍了获取Migrate.exe工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在挣扎上执行EF Migrate.exe工作。

我的解决方案有几个项目。在迁移和实体生活在项目数据。控制器和视图住在网页。

我尝试使用migrate.exe - 但是我奋力获得的第一个参数(组装)被接受。单证说:


  

大会指定包含该程序集的名称
  迁移配置类型。


我曾尝试:


  

migrate.exeMySolution \\ DataProject \\ BIN \\调试\\ Data.dll


 错误:无法加载文件或程序集D:\\\\ \\\\ MySolution数据\\\\ \\\\斌调试\\\\ data或它的DEP之一
endencies。给定的程序集名称或codeBase的无效。 (异常来自HRES
ULT:0x80131047)

任何想法是怎么回事了?


解决方案

看完<一个href=\"http://blog.cincura.net/232804-problem-could-not-load-file-or-assembly-assembly-or-one-of-its-dependencies-the-given-assembly-name-or-$c$cbase-was-invalid-exception-from-hresult-0x80131047-when-using-entity-fra/\">this, 这个和的this

我有(我觉得)你需要什么:


  1. 如果您使用migrate.exe针对.NET 4集,你需要重命名Redirect.config在封装\\ EntityFramework.5.0.0 \\工具migrate.exe.config这个复制到同一目录迁移。可执行程​​序。对于运行migrate.exe针对.NET 4.5组装你不需要这个副本中,migrate.exe.config必须不存在。

  2. 实体框架DLL的正确版本必须在同一目录migrate.exe。正确的版本是包\\ EntityFramework.5.0.0 \\ lib目录\\ net40 \\运行migrate.exe针对.NET 4集。正确的版本是包\\ EntityFramework.5.0.0 \\ lib目录\\ net45 \\运行migrate.exe针对.NET 4.5组装

  3. 如果您指定/ StartUpDirectory =不指定/装配例如路径: C:\\工具\\ migrate.exe some.dll / StartUpDirectory = C:\\项目\\ BIN \\

  4. 如果您不指定启动目录,那么你需要指定在/装配例子的完整路径: C:\\工具\\ migrate.exe C:\\项目\\ BIN \\一些。 DLL - 在这种情况下migrate.exe将无法加载some.dll的依赖关系,除非你把所有some.dll的依赖,并把它放在同一目录migrate.exe

  5. 如果你把migrate.exe作为你some.dll相同的路径,然后migrate.exe将能够使用的应用程序使用相同的EntityFramework.dll,并且可以加载所有的依赖关系,并且可以加载一些.DLL不喜欢的路径C:\\工具\\ migrate.exe some.dll

  6. 如果你把migrate.exe像我是个独立的Tools文件夹做这件事需要EntityFramework.dll的正确版本相同的目录migrate.exe,它需要的 / StartUpDirectory = &lt;保证路径,你的目标DLL是present&GT; 子句,你应该不喜欢的路径指定程序集的名称: C:\\工具\\迁移。 exe文件some.dll / StartUpDirectory = C:\\项目\\ BIN \\

  7. 继承人的PowerShell的条命令我使用的:

  $ SolutionPath =(解决路径'..')。路径
$ ToolsPath =$ SolutionPath \\建立\\ LIB \\任务DB {
  $迁移= $ ToolsPath +'迁移\\ migrate.exe
  $ migrateCommand =$迁移zasz_me.dll / StartUpDirectory = $ SolutionPath \\ zasz.me \\ BIN \\ /的connectionStringName:FullContext /startUpConfigurationFile:$SolutionPath\\zasz.me\\Web.config /详细
  写主机$ migrateCommand
  调用-Ex的pression $ migrateCommand
}

I have been struggling on executing EF Migrate.exe to work.

My Solution has couple of projects. The migrations and the entities live in the project Data. The controllers and views live in Web.

I tried using the migrate.exe - however I am struggling getting the first argument (assembly) to be accepted. Documentations says:

Assembly: Specifies the name of the assembly that contains the migrations configuration type.

I have tried:

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)

Any idea what is going wrong?

解决方案

After reading this, this, and this

I have (I think) what you need :

  1. If you use migrate.exe against a .NET 4 assembly you NEED to rename the Redirect.config available in packages\EntityFramework.5.0.0\tools to migrate.exe.config and copy this to the SAME directory as migrate.exe. For running migrate.exe against a .NET 4.5 assembly you DO NOT NEED this copy, the migrate.exe.config must not exist.
  2. The correct version of entity framework DLL must be in the SAME directory as migrate.exe. Correct version is packages\EntityFramework.5.0.0\lib\net40\ for running migrate.exe against a .NET 4 assembly. Correct version is packages\EntityFramework.5.0.0\lib\net45\ for running migrate.exe against a .NET 4.5 assembly
  3. If you specify /StartUpDirectory= do not specify the path for /assembly example : C:\Tools\migrate.exe some.dll /StartUpDirectory=C:\Project\bin\.
  4. If you don't specify a startup directory, then you need to specify the full path in the /assembly example : C:\Tools\migrate.exe C:\Project\bin\some.dll - In this scenario migrate.exe will not be able to load the some.dll's dependencies, unless you put all some.dll's dependencies and put it in the SAME directory as migrate.exe.
  5. If you put the migrate.exe in the same path as your some.dll, then migrate.exe will be able to use the same EntityFramework.dll which your app uses, and can load all dependencies, and can load the some.dll without any path like C:\Tools\migrate.exe some.dll
  6. If you put the migrate.exe in a separate tools folder like Im doing it needs the correct version of the EntityFramework.dll in the SAME directory as migrate.exe, it will need the /StartUpDirectory=<the path where you target dll is present> clause, and you should specify the name of the assembly without the path like : C:\Tools\migrate.exe some.dll /StartUpDirectory=C:\Project\bin\
  7. Heres the powershell commmand I use :

$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
}

这篇关于获取Migrate.exe工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆