Visual Studio 解决方案中从程序集到 DLL 的引用 [英] Reference from assembly to DLL in Visual Studio solution

查看:37
本文介绍了Visual Studio 解决方案中从程序集到 DLL 的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有 .NET 应用程序 App 和附加程序集 ClassLibrary,后者又使用名为 Library 的本机 DLL.所有这些都在一个解决方案中,所以我可以设置依赖项等.

Say, that we have .NET application App along with additional assembly ClassLibrary, which, in turn, uses native DLL called Library. All these are in single solution, so I may set up the dependencies etc.

问题是,我希望 Library 自动附加"到 ClassLibrary,这样当我的 App 引用它时,Visual Studio 会自动将 Library 复制到目标 bin 文件夹.

The catch is, that I want the Library to be automatically "attached" to ClassLibrary, such that when my App references it, Visual Studio will automatically copy the Library to target bin folder.

通常我通过使用预构建或后构建事件并添加自定义脚本来做到这一点.但是,嘿,所有这些都在同一个解决方案中.有没有更简单的方法来为 .NET 程序集保留这种本机 dll 引用?

Usually I did that by using pre-build or post-build events and adding custom scripts. But hey, all these are in the same solution. Is there simpler way to keep such native-dll-reference for .NET assembly?

推荐答案

您必须将本机库添加到您的项目中.如果本机库在解决方案中(不在项目中),则它仅供您参考.您必须将本机库添加到项目中,因为项目文件描述了构建行为.

You have to add the native library to your project. If the native library is in the Solution (not in the project) than it is there only for your reference. You have to add the native library to the Project because the project file describe the build behaviour.

然后将本机程序集添加到 ClassLibrary 项目,然后在属性设置中:Copy To Output DirectoryCopy if newerCopy always.

Than add native assembly to the ClassLibrary project and then in properties set: Copy To Output Directory to Copy if newer or Copy always.

这篇关于Visual Studio 解决方案中从程序集到 DLL 的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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