[英]Referencing assemblies that use NuGet packages from a project that also uses some of these packages
I have a complex library A
that consists of several c# projects producing the following assemblies: 我有一个复杂的库
A
,它包含几个生成以下程序集的c#项目:
The library is written by me, and I have full access to its source code. 该库是由我编写的,我可以完全访问其源代码。 It depends on several NuGet packages, let's say they are:
这取决于几个NuGet包,假设它们是:
These libraries (MongoDb driver and EntLib) are not installed in GAC. 这些库(MongoDb驱动程序和EntLib)未安装在GAC中。
I also have a web project B
and I want to use library A
in it as a reference to a DLL (not including projects into solution B
). 我还有一个Web项目
B
,我想在其中使用库A
作为DLL的引用(不包括项目到解决方案B
)。 The web project depends on several NuGet packages, among them: Web项目依赖于几个NuGet包,其中包括:
Versions of these packages in solutions A
and B
do not match as they are not developed synchronously. 解决方案
A
和B
中这些软件包的版本不匹配,因为它们不是同步开发的。 Library A
was developed a year ago and used as is since then. 图书馆
A
是在一年前开发的,从那时起就一直使用。
Question: what is the proper way to distribute library A
so that: 问题:分发库
A
的正确方法是什么,以便:
A
dependencies are not referenced. A
依赖项,任何解决方案都可以使用它。 A
dependencies, they do not conflict. A
依赖项版本,则它们不会发生冲突。 My current approach: 我目前的做法:
A.Core, A.Caching, A.Logging, A.MongoDb
. A.Core, A.Caching, A.Logging, A.MongoDb
。 B
uses mongocsharpdriver version 1.5 and lib A
uses version 1.1 (the versions are not that compatible). B
使用mongocsharpdriver 1.5版,而lib A
使用1.1版(版本不兼容)。 So, what shall I do? 那么,我该怎么办? What will be the correct way of dealing with conflict 'references vs. references of references'?
处理冲突引用与引用引用的正确方法是什么?
The best way to manage shared references is to create your own NuGet package for library A which, among other things, defines any dependencies (including versions) that library A relies on. 管理共享引用的最佳方法是为库A 创建自己的NuGet包 ,其中包括库A依赖的任何依赖项(包括版本)。 If you don't want to publish library A to the public NuGet feed, you can host your own feed .
如果您不想将库A发布到公共NuGet供稿,则可以托管自己的供稿 。
NuGet has some complex dependency resolution rules that will attempt to locate a dependency version that is compatible with your project and its dependencies. NuGet有一些复杂的依赖项解析规则 ,它们将尝试查找与您的项目及其依赖项兼容的依赖项版本。 Unfortunately, this still won't solve your problem in point 3 above, where your solution and its dependent library use mutually incompatible versions of the same external dependency.
不幸的是,这仍然无法解决您在上面第3点中的问题,其中您的解决方案及其依赖库使用相同外部依赖项的互不兼容的版本。 In this case, you'll just have to re-work either your solution B or library A so that they use the same version of mongocsharpdriver.
在这种情况下,您只需重新使用解决方案B或库A,以便它们使用相同版本的mongocsharpdriver。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.