August 3, 2009

.Net Assembly Probing

I have a situation where I need an application to look for assemblies in a subdirectory of the path where the executable resides. For instance, if I have an executable here:

C:\MyApp\MyApp.exe

The application will normally look for assemblies it depends on here:

C:\MyApp\

However, what if you would like to put the assemblies here instead:

C:\MyApp\MyAssemblies\

What you can do is add a few lines to your app.config for the application that looks like this.


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



Where the privatePath attribute is a semi-colon delimited list of subdirectories to look in. In this particular case, we would add this:


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