参考文件中的EF代码迁移通过nuget进行 [英] EF code migration in reference dll coming through nuget

查看:121
本文介绍了参考文件中的EF代码迁移通过nuget进行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一种情况。我们公司的框架是基于.net构建的,它由使用该框架开发的产品使用。现在这个框架首先使用EF代码。我们希望通过生成的迁移定义实现EF代码迁移,因为我们的实体位于Framework项目之一。所以我已经实现了。但是,我们正在将这个框架分配给其他产品,就像Nuget软件包(内部)一样。



现在情况是让我们说 ProductA 正在使用具有启用迁移功能的xyz.dll的软件包。现在,ProductA的开发者想要首先使用该xyz.dll迁移来升级由Framework EF代码创建的数据库,但是这个dll只是被添加为引用的dll。所以在包管理器控制台(如Update-Database)中运行命令不起作用,因为项目不在当前的解决方案中,而在参考文件dll中



我该如何解决? p>

解决方案

这实际上很容易解决,你添加nuget包的项目也需要引用EF。



您可以在您的nuget包中实际执行此功能,例如:

 <依赖关系> 
< dependency id =EntityFrameworkversion =4.2.0.0/>
< / dependencies>

在您的nuspec(显然更新版本与您正在使用的)



请参阅: http://docs.nuget。 org / docs / reference / nuspec-reference#指定依赖关系





http://docs.nuget.org/docs/reference/versioning#Specifying_Version_Ranges_in_.nuspec_Files



有关依赖语法如何工作的一些更多细节


We have a situation. Our company has Framework build on .net which is used by products developed using that Framework. Now this Framework is using EF code first. We want to implement EF Code Migration though generated migrations definitions because our entities are there in one of the Framework project. So I have implemented it. But the situation is this Framework we are distributing to other products as Nuget package (internal).

Now the situation is lets say ProductA is consuming the package which has xyz.dll which has migrations enabled in it. Now the developers of "ProductA" wants to upgrade the database created by Framework EF code first using that xyz.dll migrations, but this dll is only added as referenced dll. So running command in package manager console like Update-Database is not working because project is not in the current solution and its in reference dll

How do I solve this?

解决方案

This is actually pretty easy to solve, the project which you add your nuget package to also needs to reference EF.

You can actually enforce this inside your nuget packages with a dependency eg:

    <dependencies>
        <dependency id="EntityFramework" version="4.2.0.0" />
    </dependencies>

in your nuspec (obviously update the version with the one you are using)

See: http://docs.nuget.org/docs/reference/nuspec-reference#Specifying_Dependencies

and

http://docs.nuget.org/docs/reference/versioning#Specifying_Version_Ranges_in_.nuspec_Files

for some more details around how the dependancy syntax works

这篇关于参考文件中的EF代码迁移通过nuget进行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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