Monday, October 04, 2004

Deploy .Net Assembly in different folder

By default, the CLR will look for the assembly files(dll) in the same directory as the application(exe). If it cannot find the dll, a FileNotFound exception will be throw.

This might not be desirable if your application has a large number of dll that it reference. For example, if your application support plug-ins, you might want all the plug-ins to be put into another directory call 'plugin'.

There is 2 ways to deploy the dll into a different directory. However, this folder is relative to your application directory. You cannot deploy the dll outside your application directory.

Method 1
You can deploy the dll in a sub directory that has the same name as the dll.
For example:

You have 2 files, myapp.exe and mydll.dll. You deploy myapp.exe in your application folder, and deploy mydll.dll in a sub directory named 'mydll'.

It should look something like this :

\program files\MyGreatesApp\myapp.exe
\program files\MyGreatesApp\mydll\mydll.dll


Method 2
You can use a application configuration file to specify the private path the CLR
should search for to locate the dll.

For example, you place you exe and dll in the following directory :

\program files\MyGreatesApp\myapp.exe
\program files\MyGreatesApp\plugin\myplugin.dll

This is how your application configuration file should look like :

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

If you have multiple directory, you can specify the all the directories using a semicolon delimited string. But take note that it cannot have any space in between the semicolon.

Example :

<probing privatePath="plugin;library"/>

Labels:

0 Comments:

Post a Comment

<< Home