Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Putting the required DLLs somewhere other than the root of the output [duplicate]

I am using EmguCV for a project and when our program runs it needs some dlls like "cxcore.dll" etc. (or it throws runtime exceptions). At the moment, I put the files in the root of the output folder (selected "Copy Always" in the file's properties in Visual Studio).

However it looks a bit messy, to have about 10 different dlls just there. Is there someway where I can move it to a subfolder in the output folder and it'll still find it.

like image 275
Aishwar Avatar asked Mar 15 '10 07:03

Aishwar


2 Answers

Amazing answers so far. None right ;) Well,

yes, you can put the assemblies in separate locations.

In the corresponding application config (app.config which gets copied to your.exe.config) add:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <probing privatePath="lib" />
    </assemblyBinding>
</runtime>

According to:

http://msdn.microsoft.com/en-us/library/823z9h8w.aspx

This will make the program look into the private path (folders under it's own folder) for assemblies - much like a web application looks for /bin.

You can also put them into the GAC, but that should be avoided unless there are other reasons for this.

That being said, you really dont need to. Users wont get confused if you install the application properly in the start menu ;) I never had that problem, including projects with 50+ assemblies. Users simlpy never see them.

like image 132
TomTom Avatar answered Oct 23 '22 02:10

TomTom


To get the assemblies in a sub-directory you can copy them there manually, use a pre- or post-build event or something completely different.

To load them, you can use the AppDomain.AssemblyResolve Event, or (as noted by TomTom) the <probing> Element. From MSDN:

The following example shows how to specify application base subdirectories the runtime should search for assemblies.

<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <probing privatePath="bin;bin2\subbin;bin3"/>
        </assemblyBinding>
    </runtime>
</configuration>

The GAC is of course another place to dump your assemblies, but that wouldn't really count as a sub-directory... unless you install your application somewhere it really shouldn't be installed :P

like image 26
Svish Avatar answered Oct 23 '22 02:10

Svish