如何让 Visual Studios 构建系统了解托管 dll 的非托管依赖项? [英] How to get Visual Studios build system to understand unmanaged dependencies of managed dlls?

查看:28
本文介绍了如何让 Visual Studios 构建系统了解托管 dll 的非托管依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在构建托管代码时,Visual Studio 正确(并且递归地)将引用的托管项目的 dll 复制到正在构建的项目的输出文件夹中.

When building managed code Visual Studio correctly (and recursively) copies dlls of referenced managed projects to the output folder of the project being build.

但是,如果其中一个引用是依赖于非托管 dll 的托管 DLL,则这些非托管 DLL 不会复制到输出文件夹,即使它们在同一解决方案中的相应项目被列为托管 DLL 的依赖项.

However, if one the of those references is a managed DLL that depends on unmanaged dlls then these unmanaged DLLs are not copied to the output folder, even though their corresponding projects in the same solution and are listed as dependencies of the managed DLL.

我意识到这个问题可以通过让所有项目使用相同的输出文件夹来解决.我们已经为大多数项目这样做了,但我们更喜欢将单元测试输出文件夹分开,这会导致使用托管 Dll 和非托管依赖项的单元测试出现上述问题.

I realize that this problem can be resolved by having all projects use the same output folder. We already do that for most projects, but we prefer to keep unit test output folders separate, causing the above issue for unit tests that use a managed Dll with unmanaged dependencies.

我们现在使用的解决方案是一个预构建事件来复制必要的 DLL,但这会浪费时间并且容易出错,因为每个使用托管 DLL 的项目都需要重复它.

The solution we are using right now is a pre-build event to copy the necessary DLLs but this wastes time and is error-prone as it needs to be repeated for every project that uses the managed DLL.

因此,我想知道是否有一种方法可以让构建系统了解它应该在决定复制托管 DLL 时始终复制托管 DLL 的非托管依赖项?

I would therefore like to know if there is a way to get the build system to understand that it should always copy the unmanaged dependencies of the managed DLL whenever it decides to copy the managed DLL?

推荐答案

一种解决方法似乎是在托管 DLL 项目中添加另一个节点,命名非托管 DLL 并设置 Build Action = "None",然后 Copy to Output目录 =如果较新则复制".

One workaround seems to be to add another node to the managed DLL project, naming the unmanaged DLL and setting the Build Action = "None", and Copy to Output Directory = "Copy if Newer".

对于构建 C++/CLR 项目,我认为这可行:

For building a C++/CLR project, I think this would work:

添加节点,并将其构建工具设置为自定义构建工具.然后,在 Custom Build Step 页面中,将 Command 设置为 copy $(InputPath) $(OutDir) 并将 Outputs 设置为 $(OutDir)$(InputFileName).看起来应该可以.

Add the node, and set its build tool to Custom Build Tool. Then, in the Custom Build Step page, set the Command to copy $(InputPath) $(OutDir) and the Outputs to $(OutDir)$(InputFileName). Looks like that should work.

这篇关于如何让 Visual Studios 构建系统了解托管 dll 的非托管依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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