为什么本机DLL没有被复制到输出目录 [英] Why the native DLL is not copied to the output directory

查看:216
本文介绍了为什么本机DLL没有被复制到输出目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#项目A,它使用.net包装器DLL和本机DLL。我将.net包装器DLL添加到项目A的引用列表中。由于包装器DLL只能在本机DLL位于同一个文件夹中时使用,所以本机DLL应该被复制到项目A的输出目录中。我实现这个通过将本机DLL添加为项目A下的内容文件,并将其副本操作设置为复制(如果较新)。这是很好的。



如果C#项目B直接引用到项目A,VS将把项目A使用的所有依赖文件复制到项目B的输出目录。意味着包装器DLL和本地DLL将被复制到项目B的输出目录中。这样做也很好。



然后我还有另一个C#项目C,它只直接指代项目B而不是项目A.有趣的是看到VS会不将本机DLL复制到项目C的输出目录,这是我打算做的,否则当项目C使用项目B的功能,并寻找本机DLL来处理包装器DLL时,它不会找到它。有人可以解释为什么VS不会将本机DLL复制到项目C的输出目录中?



在VS中复制链接相关文件的机制是什么?非常感谢。

解决方案

基本上参考链不会传播,而是由最上层的程序集(exe,web网站等),以确保它具有本地或在(例如与受管理的dll)GAC中需要的一切。您将需要将文件添加到exe / web站点为复制到输出。


I have a C# project A which uses a .net wrapper DLL and a native DLL. I add the .net wrapper DLL to the reference list of project A. Since the wrapper DLL only works with the native DLL when they are in the same folder, the native DLL should be copied to the output directory of project A. I achieve this by adding the native DLL as a content file under project A and set its copy action to copy if newer. This is fine.

If a C# project B has direct reference to project A, VS will copy all dependent files used by project A to the output directory of project B. This means the wrapper DLL and the native DLL will be copied to project B's output directory as well. This works fine as well.

Then I have yet another C# project C, which only directly refers to project B, not project A. It is interesting to see that VS will not copy the native DLL to the output directory of project C, which is what I intend to do otherwise when project C uses the functionality of project B and looks for the native DLL to work with the wrapper DLL, it won't find it.

Can someone explain why VS doesn't copy the native DLL to the output directory of project C? What is the mechanism of copying chain-dependent files in VS? Many thanks.

解决方案

Basically reference-chains don't propagate, and it is up to the topmost assembly (the exe, web-site, etc) to ensure that it has everything it needs, either locally or in (for example with managed dlls) the GAC. You will need to add the files to the exe/web-site as "copy to output".

这篇关于为什么本机DLL没有被复制到输出目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆