尝试在生产环境中首先运行EF代码Migrate.exe工具失败

问题描述 投票:4回答:2

我正在使用EntityFramework版本6.1.3。

我将migrate.exe从EntityFramework版本6.1.3包工具文件夹复制到我网站的bin文件夹。

我的网站使用x86 CPU和目标框架4.5.1编译并发布到生产环境

我运行以下命令:

D:\ Sites \ MatrixPortal \ bin> migrate.exe d:\ sites \ MatrixPortal \ bin \ MatrixPortal.BL.dll / startUpDirectory =“d:\ Sites \ MatrixPortal \ bin”/ startUpConfigurationFile =“d:\ Sites \ MatrixPortal \ Web.config中”

我收到以下错误:

错误:无法加载文件或程序集“d:\ sites \ MatrixPortal \ bin \ MatrixPortal.BL”或其依赖项之一。给定的程序集名称或代码库无效。 (HRESULT异常:0x80131047)

编辑:

当我尝试这个:

迁移MatrixPortal.BL.dll / verbose

我得到其他错误:

System.BadImageFormatException:无法加载文件或程序集“MatrixPortal.BL”或其依赖项之一。尝试加载格式不正确的程序。文件名:'MatrixPortal.BL',位于System.Reflection.RuntimeAssembly的System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName,String codeBase,Evidence assemblySecurity,RuntimeAssembly locationHint,StackCrawlMark&stackMark,IntPtr pPrivHostBinder,Boolean throwOnFileNotFound,Boolean forIntrospection,Boolean suppressSecurityChecks) .InternalLoadAssemblyName(的AssemblyName assemblyRef,证据assemblySecurity,RuntimeAssembly reqAssembly,StackCrawlMark&stackMark,IntPtr的pPrivHostBinder,布尔throwOnFileNotFound,布尔forIntrospection,布尔suppressSecurityChecks)在System.Reflection.RuntimeAssembly.InternalLoad(字符串assemblyString,证据assemblySecurity,StackCrawlMark&stackMark,IntPtr的pPrivHostBinder,布尔forIntrospection )System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString,Evidence assemblySecurity,StackCrawlMark&stackMark,Boolean forIntrospection)在System.ReData.Entity的System.Reflection.Assembly.Load(String assemblyString)处。位于System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run()的System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.FindConfiguration()中的Migrations.Design.ToolingFacade.BaseRunner.LoadAssembly(String name)系统.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)在System.Data.Entity.Migrations.Console.Program.Run()处于System.Data.Entity.Migrations.Console.Program.Main(String [] args)

===预绑定状态信息===日志:DisplayName = MatrixPortal.BL(部分)警告:为程序集提供了部分绑定信息:WRN:程序集名称:MatrixPortal.BL |域ID:2 WRN:仅提供部分程序集显示名称时发生部分绑定。警告:这可能导致装订器装入错误的装配。警告:建议为程序集提供完全指定的文本标识,即WRN:由简单名称,版本,区域性和公钥标记组成。警告:有关此问题的更多信息和常见解决方案,请参阅白皮书http://go.microsoft.com/fwlink/?LinkId=109270。日志:Appbase = file:/// D:/ Sites / MatrixPortal / bin / LOG:Initial PrivatePath = NULL调用程序集:EntityFramework,Version = 6.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089。 ===日志:此绑定在默认加载上下文中启动。日志:使用应用程序配置文件:C:\ Users \ guy_b \ AppData \ Local \ Temp \ tmpC402.tmp日志:使用主机配置文件:日志:使用C:\ Windows \ Microsoft.NET \ Framework64 \ v4中的计算机配置文件。 0.30319 \ CONFIG \ machine.config中。日志:此时策略未应用于引用(私有,自定义,部分或基于位置的程序集绑定)。日志:尝试下载新的URL文件:/// D:/Sites/MatrixPortal/bin/MatrixPortal.BL.DLL。错误:无法完成程序集的设置(hr = 0x8007000b)。探测终止。

错误:无法加载文件或程序集“MatrixPortal.BL”或其依赖项之一。尝试加载格式不正确的程序。

也试过这个:http://www.azurefromthetrenches.com/command-line-entity-framework-code-first-migrations/

并创建了一个名为Redirect.config的文件,其中包含以下内容:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
                                <bindingRedirect oldVersion="0.0.0-6.1.3" newVersion="6.1.3" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

但得到与上面相同的错误:(

entity-framework ef-migrations
2个回答
1
投票

解决了!

我发布了x86目标cpu的网站项目,显然它不是真正的x86,我不知道为什么,也许是一个bug?

将Publish更改为任何cpu后,它都有效。我能够使用以下参数运行migrate.exe而不会出错:

migrate.exe MatrixPortal.BL.dll /verbose /startUpDataDirectory="D:\Sites\MatrixPortal" /startUpConfigurationFile="D:\Sites\MatrixPortal\Web.config"

1
投票

在我的情况下,我得到了错误,因为我写了migrate .\MyAssembly.dll而不是migrate MyAssembly.dll

请参阅Common Problems文档部分。

© www.soinside.com 2019 - 2024. All rights reserved.