We use Wix to build installers at my work. I've blogged about this before.

Wix comes with custom actions to create IIS App Pools and Virtual Directories. Up until today, my wix scripts all WebVirtualDirs and WebAppPools in the same component:

	<Component Id='WebApp_WithAppPool' 
		   Guid='$(var.IIsWithAppPoolSettingsComponentId)'>
        	<Condition>Not IISMAJORVERSION="#5"</Condition>
                <WebAppPool Id='MyAppPool'
                            Name='$(var.AppPool)' />
                <WebVirtualDir Id='MyVDirWithAppPool'
                               Alias='IMR/$(var.InstallDirectory)'
                               Directory='INSTALLDIR'
                               WebSite='Default'
                               DirProperties='AppDirProps'>
                    <WebApplication Id="MyAppWithAppPool" 
				    Name='[ProductName]' 
				    WebAppPool='MyAppPool'>

We recently changed the security model of this application to use a service account, but the above installer would uninstall the app pool when the application was uninstalled. When they went to install an upgraded version they would have to find someone that knew the password for the service account to enter it in the app pool settings after installing.

A little searching led me to this mailing list thread, where they recommend adding a Permanent='yes' attribute (which I didn't realize existed.)

This worked, but then my vdir doesn't get uninstalled, so I just created a new component for the app pool, made it permanent, and voila:

  • When installing
    • If the app pool doesn't exist it's created
    • If it exists we leave it alone but still put the app in it.
  • When uninstalling
    • The vdir is deleted, but the app pool is left alone.
	<Component Id="WebApp_AppPool"
		   Guid="$(var.IIsAppPoolComponentId)"
		   Permanent="yes">
       		<Condition>Not IISMAJORVERSION="#5"</Condition>
                <WebAppPool Id='MyAppPool'
                            Name='$(var.AppPool)' />
	</Component>
	<Component Id='WebApp_WithAppPool' 
		   Guid='$(var.IIsWithAppPoolSettingsComponentId)'>
        	<Condition>Not IISMAJORVERSION="#5"</Condition>
                <WebVirtualDir Id='MyVDirWithAppPool'
                               Alias='IMR/$(var.InstallDirectory)'
                               Directory='INSTALLDIR'
                               WebSite='Default'
                               DirProperties='AppDirProps'>
                    <WebApplication Id="MyAppWithAppPool" 
				    Name='[ProductName]' 
				    WebAppPool='MyAppPool'>

 

It actually took me a little while to find out about Permanent='yes', hence this blog post.