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

11,337

Solution 1

Just add your DLL to the project within Visual Studio.

  • Right click project in 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
  • Select your DLL in the Solution Viewer
  • 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.

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.

Solution 2

You can just include the dll in your project and deploy the whole thing with 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. 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.

Solution 3

If ClickOnce has the ability to carry that DLL file with it and copy it to the application folder, I would use it. 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.

Share:
11,337
Admin
Author by

Admin

Updated on July 19, 2022

Comments

  • Admin
    Admin almost 2 years

    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. 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/). 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.

    My question: I will need an installer for the application, which will manage that the .dll will install as well. I am considering ClickOnce deployment since I am using Visual C# 2008 Express Edition, but any not too expensive solution will do.

    What would you advice?

  • Peter Mortensen
    Peter Mortensen over 8 years
    This will work for DLL files. However, not for e.g. XML files by default as they will be marked "Data File" (column "Publish Status") and as a consequence not copied to the ClickOnce application's install directory during installation (see A .deploy file is not deploying an XML file). The fix is to change "Data File" to "Include".