简体   繁体   English

如何在包含第三方DLL文件的同时部署C#应用程序?

[英]How to deploy a C# application while including third-party DLL files?

To start with, I don't know much of deployment. 首先,我对部署知之甚少。 I hope my question makes sense. 我希望我的问题有道理。

I need to install/deploy a C# application to a number of desktops. 我需要将C#应用程序安装/部署到许多桌面。 It needs a third-party DLL file: A C++ library ("lpsolve55.dll", for those interested, it is a free MIP/LP solver, see lpsolve.sourceforge.net/5.5/). 它需要第三方DLL文件:一个C ++库(“lpsolve55.dll”,对于那些感兴趣的人,它是一个免费的MIP / LP解算器,请参阅lpsolve.sourceforge.net/5.5/)。 I use it in my code in the following way: 我通过以下方式在我的代码中使用它:

    [DllImport("lpsolve55.dll", SetLastError = true)]
    public static extern bool add_column(int lp, double[] column);

For testing, I have manually copied the .dll file to to project\\bin\\release , and it works fine. 为了测试,我手动将.dll文件复制到project\\bin\\release ,它工作正常。

My question: I will need an installer for the application, which will manage that the .dll will install as well. 我的问题:我需要一个应用程序的安装程序,它将管理.dll也将安装。 I am considering ClickOnce deployment since I am using Visual C# 2008 Express Edition , but any not too expensive solution will do. 我正在考虑ClickOnce部署,因为我使用的是Visual C#2008 Express Edition ,但任何不太昂贵的解决方案都可以。

What would you advice? 你有什么建议?

Just add your DLL to the project within Visual Studio. 只需将您的DLL添加到Visual Studio中的项目。

  • Right click project in Solution Viewer 右键单击Solution Viewer中的项目
  • Select Add - Existing Item 选择添加 - 现有项目
  • Browse to the DLL and click Add or the little arrow next to the Add button and Add as Link 浏览到DLL并单击“添加” “添加”按钮旁边的小箭头,然后单击“添加为链接”
  • Select your DLL in the Solution Viewer 在解决方案查看器中选择您的DLL
  • Right click it and select Properties 右键单击它并选择“属性”
  • Set Build Action to Content 构建操作设置为内容
  • Set Copy to Output Directory to Copy if newer 如果较新请将“ 复制到输出目录”设置为“ 复制

Now your file will automatically be copied into the debug or release folder. 现在,您的文件将自动复制到调试或发布文件夹中。

For deploying you can add a setup project to your solution. 对于部署,您可以向解决方案添加安装项目。 When you add the output of your first project to the setup project the DLL will automatically be added to the setup. 将第一个项目的输出添加到安装项目时,DLL将自动添加到安装程序中。

But a setup project is a completely new area. 但是一个设置项目是一个全新的领域。 So start to work with it and ask a new question if you get stuck with it. 所以,如果你遇到它,就开始使用它并提出一个新问题。

You can just include the dll in your project and deploy the whole thing with ClickOnce. 您可以在项目中包含dll,并使用ClickOnce部署整个内容。 Add it to your solution, set the build action to 'content'. 将其添加到您的解决方案中,将构建操作设置为“内容”。 Set 'copy to output directory' to 'copy always'. 将“复制到输出目录”设置为“始终复制”。 When you publish, you should be able to see the file in the publish folder. 发布时,您应该能够在publish文件夹中看到该文件。 You can also check the Application Files dialog (in the publish tab of the project properties) to make sure it's going to be included. 您还可以检查“应用程序文件”对话框(在项目属性的“发布”选项卡中)以确保它包含在内。

If ClickOnce has the ability to carry that DLL file with it and copy it to the application folder, I would use it. 如果ClickOnce能够携带该DLL文件并将其复制到应用程序文件夹,我会使用它。 It would be even better if it can check if the DLL file is present on the system (system32 folder) and use that then, so you don't have several versions of a binary on the target computer. 如果它可以检查系统(system32文件夹)上是否存在DLL文件并使用它,那将更好,因此您在目标计算机上没有多个版本的二进制文件。

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

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