Cook Computing

Junction Points

February 27, 2004 Written by Charles Cook

Jon Lam mentions junction points, an NTFS feature I've found useful when developing .NET applications. Say the output from the various projects in your build are placed in \myproject\bin and the directory where these files are installed by your product's installer is \program files\myproduct.


myproject
+--bin

program files
+--myproduct

To build a dll and run it in the myproduct directory you either have to copy the file each time you rebuild or temporarily change the output directory of the project. The first approach is too irritating to contemplate and the second means that dependent assemblies may not build correctly if their reference to the dll assumes its location is the bin directory.

The solution is to create a junction point under the myproduct directory which links to the bin directory:


junction "\program files\myproduct\bin" \myproject\bin

myproject
+--bin

program files
+--myproduct
    +--bin*

The next step is to configure probing for the application so that the junction point bin directory is searched, by using a configuration file, for example:


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

Finally delete the assemblies in the myproduct directory which you want to be picked up as you rebuild them, and when you run your application the assembly resolver's probing process will load them from the myproduct\bin directory which is really the \myproject\bin directory. Note when probing, only subdirectories of the application's appbase directory are eligible and so you can't just point privatePath to \myproject\bin.