EntityFramework CodeFirst migrations in dll with s

2019-07-19 05:42发布

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.

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.

2条回答
贼婆χ
2楼-- · 2019-07-19 06:09

Just an idea, but I wonder if the Package Manager Console will pick up assembly binding redirects in your app.config? May be worth a shot if you haven't got anywhere with this yet.

Just make sure your local and GAC assemblies have different version numbers and put the redirect info in the app.config of your migrations project as per this link: http://msdn.microsoft.com/en-us/library/7wd6ex19(v=vs.110).aspx

查看更多
冷血范
3楼-- · 2019-07-19 06:18

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

To fix your problem, either:

  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

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

    • 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

    • Versioning style

查看更多
登录 后发表回答