简体   繁体   English

Visual Studio C#,安装应用程序后未找到 DLL

[英]Visual studio C#, DLL not found after installing the application

I have created a DLL in C++ which I would like to import to my C# project.我在 C++ 中创建了一个 DLL,我想将其导入到我的 C# 项目中。 The application works when I run it in the Visual basic 2019. Later I have created a setup project, when I install the application it still works flawlessly on my computer.当我在 Visual basic 2019 中运行该应用程序时,它可以工作。后来我创建了一个安装项目,当我安装该应用程序时,它仍然可以在我的计算机上完美运行。

The problem occurs when I install it on another computer, in that case I get the following error: error当我在另一台计算机上安装它时出现问题,在这种情况下我收到以下错误:错误

The C# code: C# 代码:

[DllImport(@".\\shared_lib2.dll", CallingConvention = CallingConvention.Cdecl)]
        static extern void Connect(string str,string str1);

Ok, it seems I have found the issue.好的,我似乎找到了问题所在。 The DLL I was trying to init had dependencies.我试图初始化的 DLL 有依赖关系。 I then searched for them with dumpbin.exe and copied them to the install folder.然后我用 dumpbin.exe 搜索它们并将它们复制到安装文件夹。 Now it's working on a freshly installed VM flawlessly.现在它可以完美地处理新安装的 VM。

我遇到了这个错误,我已经通过将导入到项目中的 DEBUG 文件夹所需的 .dll 文件修复了它。

What @Broteamson suggested would technically work, but that would require to you manually add in the DLL after every build. @Broteamson 建议在技术上可行,但这需要您在每次构建后手动添加到 DLL 中。 I recommend adding the DLL to your project in Visual Studio as a dependency.我建议将 DLL 作为依赖项添加到 Visual Studio 中的项目中。 I've numbered the picture to match the instructions.我已经为图片编号以符合说明。 You'll need to:你需要:

  1. Right click on Dependencies in your project and select "Add Project References"右键单击项目中的依赖项并选择“添加项目引用”
  2. Select "Browse" and find the DLL you want to include in your project.选择“浏览”并找到要包含在项目中的 DLL。

Assuming the DLL is compatible with your project everything should work just fine.假设 DLL 与您的项目兼容,一切都应该可以正常工作。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM