我已经用C#成功构建了一个应用程序来连接高速测量传感器。该应用程序使用第三方DLL文件,该文件用于连接由硬件供应商提供的外部硬件。下面显示了有关如何连接DLL文件中的类的示例代码片段。
[DllImport("LJV7_IF.dll")]
internal static extern int LJV7IF_Initialize();
[DllImport("LJV7_IF.dll")]
internal static extern int LJV7IF_Finalize();
[DllImport("LJV7_IF.dll")]
internal static extern uint LJV7IF_GetVersion();
[DllImport("LJV7_IF.dll")]
internal static extern int LJV7IF_UsbOpen(int lDeviceId);
[DllImport("LJV7_IF.dll")]
internal static extern int LJV7IF_EthernetOpen(int lDeviceId, ref LJV7IF_ETHERNET_CONFIG ethernetConfig);
重点放在“ DLLImport”功能的使用上。为了访问DLL文件,我在解决方案路径中的名为Library的文件夹中创建了一个,然后添加了命令
copy $(SolutionDir)Library\LJV7_IF.dll $(TargetDir)LJV7_IF.dll
这样,DLL可以在成功构建后复制到bin文件夹。结果,该应用程序当前可以运行。
When the application is Published using the in-built Publish option in Visual Studio
the generated setup installs but the DLL "LJV7_IF.dll" is not copied to the application output. When the installed application is run, the DLL file cannot be located. This is the error message I get,
The Error message specifies that the application cannot locate the DLL file.
QUESTION: Is there an alternative way to reference the DLL file such that when the executable file is created, the DLL is correctly located?
The solution presented by @ Hans Passant works for this problem and has been solved. As a recap, Quote!!
“只需通过Project> Add Existing Item将其添加到项目中。确保其Build Action属性为“ Content”(默认情况下),因此安装程序项目也知道也需要部署它。如果将其设置为Copy to Output目录属性为“如果更新则复制”,则您不再需要postbuild事件。或者通过单击“应用程序文件”按钮手动进行操作。礼貌的–汉斯·帕桑特
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句