简体   繁体   English

引用的项目依赖项是从GAC而不是NuGet包文件夹复制

[英]Referenced project dependency is copying from GAC instead of NuGet package folder

I'm having a strange issue where I have a Windows Service project (A) that references another project in the solution (B). 我有一个奇怪的问题,我有一个Windows服务项目(A)引用解决方案中的另一个项目(B)。 The project B has a reference to a nuget package (in this case, protobuf-net); 项目B引用了一个nuget包(在本例中为protobuf-net); it is correctly referencing the path in the packages folder. 它正确引用packages文件夹中的路径。 However, when I build the Windows Service project A, the DLL that gets copied is a different version (which is coming from the GAC). 但是,当我构建Windows服务项目A时,复制的DLL是一个不同的版本(来自GAC)。

What's the best way to resolve this, and ensure that it's properly copying the dependency. 解决此问题的最佳方法是什么,并确保正确复制依赖关系。

I tried deleting the associated folder in the packages folder and then rebuilding Project B; 我尝试删除packages文件夹中的关联文件夹,然后重建Project B; this did result in nuget automatically downloading the files again, however I see that the reference in Visual Studio for Project B was updated to an older version in the GAC. 这确实导致nuget再次自动下载文件,但我发现Visual Studio for Project B中的引用已更新为GAC中的旧版本。 I had to remove the reference in the packages.config file, and then add it again using nuget to get it to update to using the correct path in the packages folder. 我不得不删除packages.config文件中的引用,然后使用nuget再次添加它以使其更新为使用packages文件夹中的正确路径。

I ran into this same problem and resolved it by setting "Copy Local" to false for the reference to Project B in Project A. 我遇到了同样的问题并通过将“复制本地”设置为false来解决它,以便引用项目A中的项目B.

In my case, all of my projects have the same Output path. 在我的例子中,我的所有项目都有相同的输出路径。 I have an EXE (project A) and a DLL (project B). 我有一个EXE(项目A)和一个DLL(项目B)。 The DLL has a reference to a Nuget package. DLL具有对Nuget包的引用。 When I would compile just the DLL it would copy the referenced Nuget DLL from the packages folder to the output folder. 当我只编译DLL时,它会将引用的Nuget DLL从packages文件夹复制到输出文件夹。

However, when I compiled the EXE it would overwrite that Nuget DLL with an older version from the GAC. 但是,当我编译EXE时,它将使用GAC中的旧版本覆盖该Nuget DLL。 Setting "Copy Local" to False fixed it so that the Nuget DLL only gets copied when the DLL is compiled and not when the EXE is compiled. 将“Copy Local”设置为False将其固定,以便只在编译DLL时复制Nuget DLL,而不是在编译EXE时复制Nuget DLL。

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

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