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

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.


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