是否有更好的方法来本地的dll复制到bin文件夹? [英] Are there any better ways to copy a native dll to the bin folder?

查看:378
本文介绍了是否有更好的方法来本地的dll复制到bin文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有C#包装code,从本机(C ++)DLL调用的函数。目前,我可以添加到C#DLL的引用,并且已经设置了复制本地选项设置为true。然而,本地的dll,这是一个依赖,不能被添加作为一个参考 - 所以没有复制本地选项

I have C# wrapper code that calls functions from a native (C++) dll. Currently, I can add a reference to the C# dll and have set the 'Copy Local' option to true. However the native dll, which is a dependency, cannot be added as a reference - so there is no 'Copy Local' option.

我曾尝试以下方法


  1. 使用后生成事件对本地的dll从libs文件夹复制 $(TargetFolder)

复制$(PROJECTDIR)利布斯\\ NQuantLibc.dll$(TARGETDIR)NQuantLibc.dll

在包括本机DLL作为项目的现有项目(添加 - >现有项 - >包括DLL)。该选项允许我用复制本地选项。这样做的缺点做法是,DLL总是显示为一个项目的项目。

Included the native dll as an existing item in the project (Add -> Existing Item -> Include dll). This option allows me to use the 'Copy Local' option. The downside to this approach is that the dll always shows as a project item.

我也试过显示所有文件,这让我看到了libs文件夹。然后,我包括这让我设置了复制本地选项项目中NQuantLibc.dll文件。然而,这给了我一个意外的结果。它创建了一个包含bin文件夹中的DLL中的子文件夹利布斯(如斌/调试/利布斯/ NQuantLibc.dll )。不理想,因为C#DLL无法正确地调用本地的dll,因为它不存在。

I also tried "Show All Files" which allowed me to see the Libs folder. I then include the NQuantLibc.dll file in the project which allowed me to set the 'Copy Local' option. However, this gave me a unexpected result. It created a Libs subfolder containing the dll within the bin folder (eg bin/debug/Libs/NQuantLibc.dll). Not ideal since the C# dll was not able to properly call the native dll since it was not there.

这两个以上工作上面的选项。是否有更好的方法来复制一个本地的dll到bin文件夹,这样的依赖将永远解决?另外,有一种不同的方法此类情况?

Both of the above options above work. Are there any better ways to copy a native dll to the bin folder such that the dependency will always be resolved? Alternatively, is there a different approach to this type of scenario?

推荐答案

使用项目+添加现有项,然后选择DLL。请在解决方案资源管理器窗口中添加的文件。在属性窗口中,更改复制到输出目录设置为复制,如果新的。

Use Project + Add Existing Item and select the DLL. Select the added file in the Solution Explorer window. In the Properties window, change the Copy to Output Directory setting to "Copy if newer".

这篇关于是否有更好的方法来本地的dll复制到bin文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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