在 Visual Studio 中指定非 .NET 依赖项 [英] Specifying a non-.NET dependency in Visual Studio

查看:40
本文介绍了在 Visual Studio 中指定非 .NET 依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 P/Invoke 从我的项目中调用非 .NET dll,这意味着 .dll 必须始终存在于 .exe 的目录中.

I'm calling a non-.NET dll from my project using P/Invoke, meaning that the .dll must always be present in the .exe's directory.

有没有什么办法可以告诉Visual Studio这个依赖,让它在编译的时候自动将.dll复制到输出目录,并在setup中自动包含.dll?还是我必须手动执行此操作?

Is there any way to tell Visual Studio of this dependency, so that it will automatically copy the .dll to the output directory when compiling, and will automatically include the .dll in the setup? Or do I have to do this manually?

推荐答案

您可以将此文件复制/链接到项目,并在属性窗口中将构建操作"设置为无"和复制到输出目录"" 改为 "如果更新则复制" 或 "始终复制".

You can copy/link this file(s) to the project, and in properties windows set "Build Action" to "None" and "Copy to Output Directory" to "Copy if newer" or "Copy always".

或者您可以使用预构建事件"&构建后事件",您可以在其中指定任何批处理脚本.

Or you can use a "Pre-Build Events" & "Post-Build Events" where you can specify any batch scripts.

我更喜欢第二种方式,因为这种方式比第一种更灵活.

I prefere the second option, because this way is more flexible than the first.

您还可以修改 MSBuild 文件并添加复制文件的任务.

Also you can modify a MSBuild file and add a task for copy the file(s).

这篇关于在 Visual Studio 中指定非 .NET 依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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