Wix-Setting INSTALLDIR dynamically

3k Views Asked by At

I have created a web setup msi for installing a website to iis. In product.wxs I have set the directory to WWWROOT

  <Directory Id='TARGETDIR' Name='SourceDir'>
  <Directory Id="IISROOT" Name='WebDir'>
     <Directory Id='INSTALLDIR' Name='MyWebSetup'></Directory>
  </Directory>
</Directory>

During installation the user can provide desired name for virtual directory. If the user is entering any other name other than 'MyWebSetup' say 'MyWebSetup1', then in the IIS a virtual directory named 'MyWebSetup1' and a directory named 'MyWebSetup' gets listed. Now what I want is I need to get Name='MyWebSetup' with user entered name say 'MyWebSetup1'. I have tried using custom actions and many other to get this done, but was of no use. Please somebody can provide me with a very clear solution as I am new to Wix. Any helps appreciated. Thank you.

2

There are 2 best solutions below

0
TJM On

I could solve this issue by passing the name of installdir with '.' and then using setdirectory to dynamically set the name of the installdir. While compiling, if the name is passed as '.' then the compiler just ignores it for the mean time and then if we pass the installdir name later then that name will be set.

The installdir name should be passed as follows

  <Directory Id='INSTALLDIR'
           Name='.'>

The setdirectory is passed as follows. [VIRTUALDIR] is the name of virtual directory accepted from user while installation.

 <SetDirectory Id="INSTALLDIR" Sequence="execute" Value="[IISROOT][VIRTUALDIR]\">NOT   Installed</SetDirectory>

Hope it helps somebody.

0
gmcve On

I had a similar problem but with other folders under the [INSTALLDIR], BIN and Service folders.

Find the IIS root path in the registry

 <Property Id="IISROOTPATH">
  <RegistrySearch Id="FindIISRootPath" Root="HKLM" Key="SOFTWARE\Microsoft\InetStp" Name="PathWWWRoot" Type="directory" />
</Property>

Setting the directory value with SetDirectory which runs before CostFinalize in the execute sequence

<SetDirectory Id="INSTALLDIR" Sequence="execute" Value="[IISROOTPATH][VIRTUALDIR]">NOT Installed</SetDirectory>
<SetDirectory Id="SERVICEFOLDER" Sequence="execute" Value="[INSTALLDIR]\Services">NOT Installed</SetDirectory>
<SetDirectory Id="INSTALLDIRBIN" Sequence="execute" Value="[INSTALLDIR]\bin">NOT Installed</SetDirectory>

Then the directory structure

<Directory Id="TARGETDIR" Name="SourceDir">
  <Directory Id="IISROOTPATH">
    <Directory Id="INSTALLDIR" Name="MyWebSetup">
      <Directory Id="INSTALLDIRBIN" Name="Bin">
            <!-- BIN Dicrectory -->
      </Directory>
      <Directory Id="SERVICEFOLDER" Name="Services">
            <!-- SERVICE FILES -->
      </Directory>
    </Directory>
  </Directory>
</Directory>

Here is another similar question