Sharing ASP.NET Files?

If you need to share web files (masterpages, skins etc.) among several web projects there are a few ways to do this. In the following few words I'll try to briefly explain some of these.

Say you have a number of very nice masterpages that you want to use in all of your companys asp.net applications. For simplicity let's assume the following directory layout:

 

\webroot

\ApplicationA

\ApplicationB

\ApplicationC

\Shared

      \masterpages

 

Now how do you get the masterpages below each of your applications?

 

IIS Virtual Directories

Under each of your Applications you simply create a virtual directory named masterpages (pointing this to \WebRoot\SharedFiles\masterpages). To use this you will need to work on a Internet Information Server and cannot use the built-in development web server that ships with Visual Studio 2005.

 

NTFS reparse points /junction points

Under each of your Applications you create a NTFS re-parse point named masterpages and pointing to \WebRoot\SharedFiles\masterpages. This trick will allow you to develop using the Development Web Server and hence does not require IIS to be installed on your development machine.

Se here for more information or download the junction tool at sysinternals site

 

"Add as Link"

In Visual Studio you can add existing items to a project - there is a very nice feature that allows you to add an existing item as a link (push the little arrow on the "Add" button). Sadly it does not seem to work for Web Projects . It works for Web Application Projects but... the master page references in your solution will get an unfortunate path as you will traverse above the root and probably get the following error when you run the page:

Cannot use a leading .. to exit above the top directory.

UPDATE: Developers running 2000/2003/XP should be aware of the effects - se here