NuGet 包:我们是否需要将它们添加到引用项目和被引用项目中?
这听起来可能微不足道,但我仍在尝试了解这里发生的事情。
我的 VSTO 加载项包含以下项目(VS2022、.NET Framework 4.8):
- Addin(VSTO 加载项,参考文献 #2)
- View(WPF 控件库,参考文献 #3)
- VM(类库,参考文献 #4)
- DataAccess (类库,引用 RestSharp nuget 包)
当我构建项目时,#4 将其 DLL 以及 RestSharp DLL 复制到其输出文件夹。随后,#3 将其自己的 DLL 以及来自 #4 的两个 DLL 复制到其输出。但#2 不会将 RestSharp DLL 复制到其输出,仅复制 View、VM 和 DataAccess DLL。 #1 也遵循该套件并忽略 RestSharp DLL。
为什么?这与数据访问针对 .NET Standard 2.0(与针对 .NET Framework 4.8 的其他层不同)这一事实有什么关系吗?
我已经通过将 RestSharp 的 NuGet 引用添加到项目 #2 来解决这个问题,但对我来说这感觉像是一个 hack。我只是想了解 Visual Studio 或 MSBuild 如何决定是否包含引用项目的依赖项。
This may sound trivial, but I'm still trying to understand what's going on here.
My VSTO add-in contains the following projects (VS2022, .NET Framework 4.8):
- Addin (VSTO add-in, references #2)
- View (WPF control library, references #3)
- VM (Class library, references #4)
- DataAccess (Class library, references RestSharp nuget package)
When I build the project, #4 copies its DLL as well as RestSharp DLL to its output folder. Thereupon #3 copies its own DLL as well as the two DLLs coming from #4 to its output. But #2 does not copy RestSharp DLL to its output, only View, VM and DataAccess DLLs. #1 also follows the suite and ignores RestSharp DLL.
Why? Has this got anything to do with the fact that Data Access is targeting .NET Standard 2.0, unlike other layers which are targeting .NET Framework 4.8?
I have fixed the problem by adding RestSharp's NuGet reference to project #2 as well, but it feels like a hack to me. I'm just trying to understand how Visual Studio or MSBuild decides whether or not to include dependencies of referenced projects.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我正在努力解决同样的问题,我遇到了这个。
我想你就在这里:
现在我将实施你的黑客解决方案。
I was struggling with the same problem and I came across this.
I think you were right here:
For now I will be implementing your hack solution.