views:

149

answers:

2

I see that junctions are a common way of referencing shared code in many projects. However, I have not seen them used in web applications before.

Our team is exploring the possibility of abandoning virtual directories in favor of junctions to simplify our build process. My goal is to compile a list of pros and cons in order to make an informed decision regarding this change.

Is it more appropriate to use junctions or virtual directories on web application projects?

Environment is ASP.NET, IIS6/IIS7, VS.NET.

+1  A: 

In case with virtual folders you need IIS installed on each environment. However with both approaches you need to manually maintain all references after each change (For example situation when someone added one more reference), which is not convinient.

Consider using VCS with referncing system. For example SVN with externals. In that case you will have:

  1. Automatic update of references on each environment.
  2. Ability to have references in different versions of external code. This will avoid situations when it is needed to change all dependent applications after each external code change.
Yauheni Sivukha
That is a really cool feature, I will see if there is a perforce equivalent.
Kevin
+1  A: 

Virtual directories vs. junctions is like comparing apples to pears: they both create sort of a virtual copy of a directory, as well as apples and pears are both fruits, but the comparison ends there.

First off, since Windows Vista, the new thing is symbolic links (which are essentially the same as junctions but can also point to a file or remote SMB path).

Symbolic links enable you to, for example, share every part of a web application except its Web.config and a stylesheet. This is something virtual directories can never do.

Also, virtual directories participate in ASP.NET's change monitoring. If you try and delete (a file or) directory from within your application, for instance, ASP.NET kills your app after the request completes, resulting in loss of session, etc. If instead of using a virtual directory, you use a symbolic link, the change will not be noticed and your app will keep on churning.

It's important to keep in mind that symbolic links are not an everyday feature in Windows. Yes, you can see that a file or directory is linked in Explorer, but it's not instantly visible to what it is linked. Also, from code it is much harder to see if a file is linked, so if you accidently delete the file that is being linked to from a million symbolic links, all those symbolic links suddenly 'stop existing'.

Symbolic links also speed up deployment of multiple instances of the same application, since the only thing you have to do is copy a few actual files, and then create symbolic links to the source files for all the rest.

ErikHeemskerk
You can run virtual directories as applications in IIS7 (don't know the exact term) which is what we do and it works quite well. This solves some of the problems you mentioned.
Kevin
The other gripe I have with junctions/symlinks is it causes duplication in the IDE. For example, if I have a symlink for an "admin" web project it will display twice. It still needs to exist in the project due to references. Overall, junctions seem like an extra step that don't give many benefits for web development. Ex: http://kevinx.net/images/repeat1.png
Kevin