简体   繁体   English

为什么一个.net库需要引用其他.net库的依赖关系

[英]Why one .net library needs the reference of the dependency of other .net library

I am facing a weird problem. 我面临一个奇怪的问题。 I have multiple .net standard class projects in my solution. 我的解决方案中有多个.net标准类项目。 There is one .net standard 2.0 class library project called Messaging ( .csproj ) which uses ActiveMQ to push and read data from it. 有一个名为Messaging( .csproj )的.net 标准2.0类库项目,该项目使用ActiveMQ来推送和读取其中的数据。 This project reference to Apache.NMS library. 该项目参考Apache.NMS库。 Now I have another project called Core ( .csproj ) which references to the Messaging project. 现在,我有另一个名为Core.csproj )的项目,它引用了Messaging项目。 During the constructor call of the class inside Messaging project in Core project, I get the error that System could not find Apache.NMS dll. 在Core项目的Messaging项目内的类的构造函数调用期间,我收到系统找不到Apache.NMS dll的错误。 If I add this reference in the Core project then everything works fine but I really do not understand why this is happening. 如果在Core项目中添加此引用,则一切正常,但我真的不明白为什么会这样。 With a pure .net framework thing, I never faced this issue. 使用纯.net框架,我从来没有遇到过这个问题。 Separate projects with their own references and working independently. 使用自己的参考文献将项目分开,并独立工作。 Can anyone help with it? 有人可以帮忙吗? I have added all references from nuget 我已经从nuget添加了所有引用

After lot of research i found the solution of this problem. 经过大量研究,我找到了解决此问题的方法。 What was happening is in the bin folder of the .NET framework / standard project the dependent dll of the referenced projects were not getting copied. 发生的是在.NET Framework /标准项目的bin文件夹中,未复制引用项目的相关dll。

Solution for .NET Framework project: Open .csproj file and add below line in the first tag .NET Framework项目的解决方案:打开.csproj文件,并在第一个标记中添加以下行

<RestoreProjectStyle>PackageReference</RestoreProjectStyle>

Solution for .NET Standard / Core project: Open .csproj file and add below line the first tag .NET Standard / Core项目的解决方案:打开.csproj文件,并在第一个标记行下方添加

<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

Now compile the projects and you will see all the required dll's are present in the bin folder. 现在编译项目,您将看到bin文件夹中存在所有必需的dll。 Hope this help someone else who is facing the same issue. 希望这可以帮助面临相同问题的其他人。

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

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