January 21, 2009 by Alistair Deneys
This is another post which starts out with me reading another post 🙂 . I was reading the Molten Core blog which is written by Thomas Eldblom (fellow MVP) and Jens Mikkelsen. Thomas published a post in which he points out the large number of PNG icon files included in Sitecore. Sitecore contains an extensive icon library consisting of 1,000’s of files. And each of these files is provided in several resolutions to improve the quality on screen. Have you ever tried zipping up an existing Sitecore solution? It takes a while. Not because it’s huge, but because there are so many little files. Same with applying attributes (security) to a folder containing a Sitecore solution.
I have often thought about somehow removing the icons folders and sharing them amongst several Sitecore instances. Like most Sitecore devs, I have several Sitecore instances on each of my machines. If you had to move even just one of these sites from box to box, such as taking a site home on the laptop to work on, it’s a pain.
One thing about reading blogs through RSS; You miss out on the comments. Thomas points out the issue in his post, but there are some great solutions to the problem, and discussion, in the comments.
Alexey Rusakov from Sitecore tells us about the different ways in which Sitecore have tried to minimise the impact of the situation. Mark Cassidy (fellow MVP) from CorePoint told us that Per Bering from Codehouse compiled all the images into a resource DLL and used a custom HTTP Module to serve from the resource DLL. Jakob Christensen from Sitecore pointed out you could use virtual directories in IIS to remap the icon folders to a single shared location. He even posted a NAnt build file which would do this for you. While reading all this I thought “If only we had symbolic links in Windows like we have in *nix. That would solve the problem.”
Seeing all these great comments got me motivated to rewrite Jakob’s build script in MSBuild. I used to be a huge fan of Ant and NAnt, but since Microsoft bought out MSBuild with .net 2.0 I have usually found everything I need in that. Every Visual Studio project file is actually an MSBuild project file. So I got to work on making this happen.
Out of the box, MSBuild can’t talk to IIS. But MSBuild is very extensible, and the MSBuild community tasks provide extensions to allow you to communicate with IIS. Unfortunately I couldn’t get this working with Vista 😦 (perhaps I didn’t try hard enough.) So I looked around for a different way of doing it. MSBuild also let’s you execute any command through the “Exec” task. IIS 7, which is the version which ships with Vista, provides a command line tool called APPCMD (find it at %systemroot%\system32\inetsrv\APPCMD) which allows you to manage IIS from the command line. I found this page very helpful in working out how to create virtual directories.
But seeing as though I was just using Exec, I decided to change my script from MSBuild to a plain old batch file. It was while I was trawling through help files trying to remember how to check if a script argument (%1) was not provided that I stumbled across a new command I hadn’t seen before. MKLINK.
MKLINK allows you to create symbolic links in Vista and Windows 2008…
I can create symbolic links in Vista??!!?
I MISSED THE MEMO!
That’s right, as of Vista (sorry XP guys) we now have symbolic links. I was ecstatic. I have been longing for this minor feature for so long in Windows.
So now it’s as easy as:
Move an existing Theme folder to a location where it can be shared amongst all your Sitecore sites such as c:\inetpub\Themes.
Delete all the Theme folders under each Sitecore website (perhaps you should check first and make sure you’re not losing any files).
Create a symbolic link under the Sitecore site to the shared location.
cd c:\inetpub\mysitecoresite\website\sitecore\shell\ mklink /d Themes c:\inetpub\Themes
Symbolic links operate at the file system level, below IIS. To users and applications it’s as if this is a real file. Now this is going to save me a lot of headaches.
Yay symbolic links!