指定在Visual Studio中non-.NET依赖Studio、Visual、NET、non

2023-09-03 04:53:38 作者:愁绪入梦遥

我打电话从我的项目中使用P / Invoke,这意味着该.dll必须始终present的.exe文件的目录non-.NET DLL。

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文件自动复制到输出目录,并会自动包含在安装该.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?

推荐答案

您可以将此文件(S)拷贝/链接到项目,并在属性窗口设置生成操作为无和复制到输出目录复制,如果新或始终复制。

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".

或者你可以使用一个pre-生成事件及放大器; 生成后事件在这里你可以指定任何批处理脚本。

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

余prefere第二种选择,因为这种方式比第一更加灵活。

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

你也可以修改的MSBuild文件,并添加一个任务复制的文件(S)。

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