Welcome to Dovetail Software Blogs : Sign in | Join | Help
Creating Windows Installers: Web Applications and Virtual Directories

So far on our journey into building windows installers we have gone from just getting started to generating Wix content for all the files in your application. There is an important little something something missing from our toy installer. Pleats (fake product of Pants Enterprises) is supposed to be a web application that runs on IIS. It would be great to add support in the installer to create a virtual directory for the web application. With Wix this is quite easy. Here we go.

A virtual directory for your web application

I like to compartmentalize my units of install where practical. Because having the installer integrate with IIS and create a virtual directory is completely different than copying files I feel that this piece of the install belongs in its own component.

<Component Id="pleatsIISIntegration" Guid="{63C11DB0-9ED2-4b63-9A4C-9A5C4C8CD599}"> <WebVirtualDir Id="pleatsVirtualDirectory" Directory="INSTALLDIR" Alias="Pleats" WebSite="DefaultWebSite"> <WebApplication Id="pleatsWebApplication" Name="Pleats"/> </WebVirtualDir> </Component>

The XML above is declaring that a virtual directory called Pleats enabled as a web application should be created under the Default Web Site. The Default Web Site in this case is a reference to a <WebSite> element we will add elsewhere. The <WebVirtualDir> needs to have a <WebApplication> when you are deploying classic ASP or ASP.Net web applications.

... </Directory> <WebSite Id="DefaultWebSite" Description="Default Web Site"> <WebAddress Id="AllUnassigned" Port="80" /> </WebSite> <Feature Id="Complete" Level="1"> ...

Above we define the web site that is being referenced by our IIS integration.

Oops need to link to the server custom action library

If you add these two blocks of XML to your .wxs file and try to build the installer using the NAnt build automation I created in my previous posts you will get a linker error because we are now using Wix schema elements that are dependant on the Server Custom Action library.

(project root)>.\tools\nant\nant build-installer

NAnt 0.85 (Build 0.85.2478.0; release; 10/14/2006)
Copyright (C) 2001-2006 Gerry Shaw
http://nant.sourceforge.net

build-installer:

     [exec] Microsoft (R) Windows Installer Xml Compiler version 2.0.5325.0
     [exec] Copyright (C) Microsoft Corporation 2003. All rights reserved.
     [exec] pleats.wxs
     [exec] Microsoft (R) Windows Installer Xml Linker version 2.0.5325.0
     [exec] Copyright (C) Microsoft Corporation 2003. All rights reserved.
     [exec] C:\projects\pleats\wix\pleats.wxs : error LGHT0112 : Unresolved reference to symbol 'CustomAction:ConfigureIIs' in section 'Product:A263E591-B290-4DB2-BF08-0C6FF24959A3'.

To fix this problem you just need to update the linker execution (light.exe) with a reference to the sca.wixlib here is the updated NAnt target for building the installer.

<target name="build-installer" depends="release-properties"> <!-- for wix preprocessor so that the location of pleats files are propagated into the wxs --> <setenv name="pleats.dir" value="${release.dir}"/> <delete> <fileset> <include name="${wix.dir}/*.wixobj"/> </fileset> </delete> <exec program="${wix.dir}\candle.exe" workingdir=".\wix" commandline="pleats.wxs " /> <exec program="${wix.dir}\light.exe" workingdir=".\wix" commandline="pleats.wixobj ${wix.dir}\wixui.wixlib ${wix.dir}\sca.wixlib -loc ${wix.dir}\WixUI_en-us.wxl -out ${release.dir}\pleats.msi"/> </target>

Build It, Install It

Building the installer should now work that the Server Custom Actions are linked in. Let's take a look at what Internet Information Services Manager on Windows XP looks like after the installer is completed.

pleats-iis-snapin_thumb[3]

Conclusion

There is a lot more customization you can do for web application configuration. For example, want to run your web applications in their own Application Pool  use <WebAppPool>. If you using the excellent MonoRail web application framework and you want your installer to register the .castle file extension to be handled by ASP.Net I believe you can use <WebApplicationExtension> to do this rather than doing it manually.

Posted: Wednesday, December 12, 2007 5:31 PM by kmiller

Comments

Joshua Flanagan said:

I'm really enjoying the series - keep it up - Wix is one of the things I've wanted to dive into. I've done some minimal work with it, but your posts definitely make it more accessible.

Just curious (I could probably check the docs)... do you know of any way to query the default website root on the destination machine, so that you can use that as your target deployment folder?

For example, instead of deploying to c:\program files, I'd rather deploy the website to c:\inetpub\wwwroot, or whatever the root folder is for the default website.

# December 12, 2007 8:47 PM

Kevin Miller said:

Joshua Flanagan had a question about install directories for web applications . He asks: &quot;Do you

# December 13, 2007 12:17 PM

Kevin Miller said:

I recently built a small Monorail application and used my Wix-fu to build a deployment for it and thought

# March 7, 2008 5:44 PM

Links Today (2008-03-08) said:

# March 8, 2008 10:19 AM