具有强名称的 dll 中的 EntityFramework CodeFirst 迁移 [英] EntityFramework CodeFirst migrations in dll with strong name

查看:23
本文介绍了具有强名称的 dll 中的 EntityFramework CodeFirst 迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 EntityFramework 中遇到迁移 api 问题.我的 DataContext 和包含在 dll 中的实体具有强名称(用证书签名),当我部署我的应用程序时,它会将 dll 放在 GAC 中.因此,当我在包管理器控制台中使用迁移命令时,它总是使用 GAC 中的 dll 而不是项目文件夹中的 dll.因此,要在模型更改后添加新迁移,我需要将 dll 部署到 GAC,然后重新启动 Visual Studio,然后运行 ​​Add-Migration.

I have a problem with migrations api in EntityFramework. My DataContext and Entities contained in dll that have strong name (signed with certificate) and when i deploy my application it places dll in GAC. So when i am using migration commands in Package Manager Console it always using dll from GAC instead of dll in project folder. So to add new migration after model changes i need to deploy dll to GAC, then restart Visual Studio and after this run Add-Migration.

有没有办法强制使用项目中的 dll?我曾尝试将 AppDomainBaseDirectory 参数与目标一起用于项目输出的 Debug 文件夹,但无济于事.

Is there a way to force using of dll from project? i have tried to use AppDomainBaseDirectory parameter with target to Debug folder of project output, but it does not help.

推荐答案

对于相同的程序集版本,GAC 的优先级高于区域设置程序集,请查看 这篇文章.

GAC has higher priority than locale assembly for the same assembly version, check this article.

要解决您的问题,请执行以下任一操作:

To fix your problem, either:

  1. 在开发过程中取消选中签名"选项卡中的签署程序集"(比重新启动 Visual Studio 好)
  2. 使用 Build Version Increment Add 手动或自动增加程序集版本-在覆盖加载GAC

  1. Uncheck the "Sign the assembly" in the Signing Tab during development (better than restart visual studio) or
  2. Increase the assembly version either manually or automatically using Build Version Increment Add-In to override loading the GAC

如链接的评论中所指定,为 VS2012 安装.

As specified in the link's comment, to install for VS2012.

  • 安装 BuildVersionIncrement_VS2010
  • BuildVersionIncrement.AddinBuildVersionIncrement.dllC:\Users\[User]\Documents\Visual Studio 2010\Addins 复制到C:\Users\[用户]\Documents\Visual Studio 2012\Addins
  • BuildVersionIncrement.Addin 10.0 编辑为 11.0
  • 设置程序集版本控制样式(主要、次要、构建、修订).对于自动构建,修订段就足够了

  • Install BuildVersionIncrement_VS2010
  • Copy BuildVersionIncrement.Addin and BuildVersionIncrement.dll from C:\Users\[User]\Documents\Visual Studio 2010\Addins to C:\Users\[User]\Documents\Visual Studio 2012\Addins
  • Edit BuildVersionIncrement.Addin <Version>10.0</Version> to 11.0
  • Set the assembly versioning style (major, minor, build, revision). for automatic build, revision segment would be sufficient

这篇关于具有强名称的 dll 中的 EntityFramework CodeFirst 迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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