5
votes

I am working on a C# .NET project in Visual Studio 2010. I am integrating a hardware peripheral that has a DLL. I reference the DLL file in my project and the code compiles/builds without any errors. When I run my application I get a runtime error saying that it is looking for another DLL file. It appears that the DLL I reference in my project has 42 other DLLs that it depends on. When I place these 42 DLLs in the output directory (bin/debug) the application runs just fine.

My questions is this: what is the best way to manage these extra DLL files when Visual Studio doesn't recognize them as dependent libraries?

4
sounds like you will need to copy those .dll's over every time or you can GAC the .DLL's or you can set the .dll properties to copy local when you compile or deploy.. not sure if adding the .dll's as a resource would work for you either but you may want to try that as well.. - MethodMan
You can try add post build action to project. look at: stackoverflow.com/questions/12384628/… - gabba
Did you check with whoever provided the libraries on what is the right approach? They may already have recommendations or even strict requirement on how to do so - i.e. if there are technical reason (i.e. registry key/configuration) or legal (can't copy files separately). - Alexei Levenkov

4 Answers

6
votes

This scenario does resemble a lot to deploying SQL Server Compact files. In that context it's called Private File–Based Deployment.
It also requires some external (unmanaged) DLLs that the application will depend on.

What it boils down to is to include the DLLs in your project and set their Copy to Output Directory properties to Copy if newer. They will then be copied to the destination folder after a successful build.

EDIT:
Based on your comment, it seems to you are having problems at install time of you application (something you completely fail to mention in your question), and you have written a Custom Action for your installer to copy these 42 DLLs to your target.
There's no need for a CA to do that. Simply right click on your installer project -> View ->File System. Select the Application Folder, in the right hand side right click and select Add File and add your 42 DLLs.

2
votes

If you mean to manage these files at compile-time you can add a post-build event to the project to copy all of the necessary files over to the output directory. Add flags to xcopy here to only copy over if changed.

If you mean at run-time an installer would be your best solution.

1
votes

Or you could combine them using something like ILMerge to combine the assemblies. And you just add a reference to the resulting assembly.

How to merge multiple assemblies into one?

0
votes

You should work on creating an Installer package, almost all Installers will bring in all of the dependencies of referenced dll's if the projects outputs are configured as needed for the installer. It is the only way I can think of to dynamically have your non-referenced dependencies be automatically brought in.