Friday, April 27, 2007

Organizing .NET Assemblies Better using Probing

For those of you who would like to keep the exes and application config in a single folder and organize assemblies (dlls) in a separate folders. This tip would come handy.

This is applicable to both Windows and Web Applications.

In web applications you can use sub folders inside your bin directory to organize your dlls to form a logical structure.

In win application you keep the exe and the app.config in the same directory and organize your assemblies in another directory

For example
Under the Win Application folder I have kept the .exe and app.config and created a sub folder called bin and copied all the assemblies to it.

In order to tell the CLR that our assemblies are present inside the bin directory. All you have to do is make a probing entry under the configuration setting. After this the compiler will look in the bin folder and find the assemblies. You can specify more than one folder.


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


Please note that there is a slight preformance hit as it has to check in another directory but considering the user need not have to search the files to find the exe in large applications it may be worth it.

To know more about probing element you can refer msdn

Happy programming

Labels: