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

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

问题描述

说,我们拥有.NET应用程序 App 以及附加的程序集 ClassLibrary ,后者依次使用本机DLL,称为 Library 。所有这些都在单个解决方案中,所以我可以设置依赖项等。

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.

通常,我通过使用构建前或构建后事件来做到这一点并添加自定义脚本。但是,所有这些都在同一个解决方案中。

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?

推荐答案

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

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项目中,然后在属性集中添加以下内容:复制到输出目录如果较新则复制始终复制

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天全站免登陆