为什么本机DLL没有被复制到输出目录 [英] Why the native DLL is not copied to the output directory
问题描述
如果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屋!