简体   繁体   English

2 个组件中引用的 Nuget package 不起作用

[英]Nuget package referenced in 2 assemblies does not work

I have a solution that is built like that:我有一个这样构建的解决方案:

ProjectA -> Assembly2 -> Assembly1 -> NuGet Package (Newtonsoft.JSON)项目A -> Assembly2 -> Assembly1 -> NuGet Package (Newtonsoft.JSON)

I'm currently developing on Assembly2, which has a dependency to Assembly1.我目前正在开发 Assembly2,它依赖于 Assembly1。 I debug with ProjectA.我用 ProjectA 调试。 So long, the Newtonsoft.dll is copied to my bin folder, and everything works.这么久,Newtonsoft.dll 被复制到我的 bin 文件夹中,一切正常。

Now I want to use Newtonsoft directly in my Assembly2, so I added it as NuGet Package.现在我想在我的 Assembly2 中直接使用 Newtonsoft,所以我将它添加为 NuGet Package。 After that, the Newtonsoft.dll is no longer copied to the bin folder.之后,不再将 Newtonsoft.dll 复制到 bin 文件夹中。

I tried to download the Newtonsoft.dll directly (or use the Newtonsoft.dll from Assembly1 directly via 'Browse...').我尝试直接下载 Newtonsoft.dll(或直接通过“浏览...”从 Assembly1 使用 Newtonsoft.dll)。 This works, too.这也有效。 It seems, that this problems only occur, when I use NuGet in Assembly2.看来,这个问题只发生在我在 Assembly2 中使用 NuGet 时。 Can someone explain this behaviour?有人可以解释这种行为吗?

I used the exact same Version of Newtonsoft.我使用了完全相同的 Newtonsoft 版本。

Puzzling for sure.肯定令人费解。 From your description that ought to be fine, but...根据你的描述应该没问题,但是...

"Transitive dependencies" are your friend. “传递依赖”是你的朋友。 If assy1 references NS.Json, and assy2 refs assy1, then NS.Json is available to assy2.如果 assy1 引用 NS.Json,而 assy2 引用 assy1,则 NS.Json 可用于 assy2。 There is no need to ref NS.Json from assy2.无需从 assy2 引用 NS.Json。

This is a-good-thing.这是一件好事。 It means that some versioning hell is removed.这意味着删除了一些版本控制地狱。 If you want to upgrade NS.Json then you only have 1 place to do that.如果你想升级 NS.Json 那么你只有一个地方可以这样做。 The ref is not scattered all over your projects. ref 并不分散在您的项目中。 This works well if you also follow the good practice of having a "clean" dependency graph.如果您还遵循拥有“干净”依赖图的良好做法,这将很有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM