Nuget:在不添加引用的情况下指定依赖项 [英] Nuget: specify dependency without references being added

查看:28
本文介绍了Nuget:在不添加引用的情况下指定依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包(比如 MyStuff.Data)需要 EntityFramework(和其他)才能工作,但只能在内部使用.我不希望每个使用 MyStuff.Data 的项目也引用 EntityFramework(以及所有其他项目),但 dll 总是需要在那里.

I have a package (say, MyStuff.Data) that requires EntityFramework (and others) to work, but only internally. I don't want every project that uses MyStuff.Data to also reference EntityFramework (and all those others), but the dll always needs to be there.

有什么方法可以将 EntityFramework 添加为 MyStuff.Data 的依赖项(以便它在包文件夹中获取 EntityFramework.dll),但没有向使用它的每个项目添加引用?

Is there any way I can add EntityFramework as a dependency of MyStuff.Data (so that it picks up EntityFramework.dll in the packages folder), but without a reference being added to each project that consumes it?

推荐答案

没有没有.一种选择是嵌入 EntityFramework dll 并将其发送到您自己的包中,并明确说明在安装期间应在目标项目中添加哪些引用.您可以使用包的 nuspec 中的 metadata 元素指定此项.可以在此处的文档中找到更多信息:http://docs.nuget.org/docs/reference/nuspec-reference#Specifying_Explicit_Assembly_References

No there is not. An option could be to embed the EntityFramework dll and ship it inside your own package, and explicitly state which references should be added in the target project during installation. You can specify this using the metadata element in the nuspec of you package. More information can be found in the docs here: http://docs.nuget.org/docs/reference/nuspec-reference#Specifying_Explicit_Assembly_References

请注意,嵌入特定版本的依赖项是对所有消费者的限制性约束,这意味着作为包生产者,您将推动消费者可以并且将使用的 EF 版本......情况不太好.

Notice that embedding a specific version of a dependency is a limiting constraint on all your consumers, which means that you, as a package producer, will be driving which version of EF your consumers can and will be using... which is not a good situation to be in.

最好尝试抽象出任何非受控 (EF) 依赖项并将真正的实现选择留给消费者(或者您提供包含实现的单独包,因此您的消费者仍然可以选择加入并使用您的).

Preferably, you try to abstract out any non-controlled (EF) dependency and leave the real implementation choice to the consumer (or you provide a separate package containing the implementation, so your consumers can still opt-in and use yours).

这篇关于Nuget:在不添加引用的情况下指定依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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