6

I've a project using IIS, and I want to create an installer for it with Wix. I've created the .msi installer for the app successfully, and I'm creating a Bundle installer for it, which will install the prerequisites and after that my application.

Here's the Bundle's code:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
  xmlns:util="http://schemas.microsoft.com/wix/UtilExtension"
  xmlns:bal="http://schemas.microsoft.com/wix/BalExtension">
  <Bundle Name="Bootstrapper" Version="1.0.0.0" Manufacturer="VilmosNagy" UpgradeCode="844c755f-f02b-4dd3-8b9c-af2498f3128c">
    <BootstrapperApplicationRef Id="WixStandardBootstrapperApplication.RtfLicense" />
    <Chain>
      <PackageGroupRef Id="NetFx45Web"/>
      <PackageGroupRef Id="SQLServerExpress"/>
      <!-- <MsiPackage SourceFile="path\to\your.msi" /> -->
    </Chain>
  </Bundle>
</Wix>

My question is, how can I install (or enable?) the IIS, IF not installed?

Thanks!

Nagy Vilmos
  • 1,878
  • 22
  • 46

5 Answers5

14

Based on Harbinder Singh's answer, here's my solution:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
     xmlns:util="http://schemas.microsoft.com/wix/UtilExtension"
     xmlns:bal="http://schemas.microsoft.com/wix/BalExtension">
    <Bundle Name="Bootstrapper" Version="1.0.0.0" Manufacturer="VilmosNagy" UpgradeCode="844c755f-f02b-4dd3-8b9c-af2498f3128c">
        <BootstrapperApplicationRef Id="WixStandardBootstrapperApplication.RtfLicense" />

    <Chain>
      <PackageGroupRef Id="InstallIIS"/>
    </Chain>
    </Bundle>
  <Fragment>    
    <PackageGroup Id="InstallIIS">
      <ExePackage
                  Id="IIS_part0"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: IIS-WebServerRole"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:IIS-WebServerRole"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part1"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: IIS-WebServer"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:IIS-WebServer"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part2"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: IIS-CommonHttpFeatures"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:IIS-CommonHttpFeatures"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part3"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: IIS-StaticContent"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:IIS-StaticContent"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part4"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: IIS-DefaultDocument"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:IIS-DefaultDocument"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part5"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: IIS-DirectoryBrowsing"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:IIS-DirectoryBrowsing"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part6"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: IIS-HttpErrors"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:IIS-HttpErrors"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part7"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: IIS-HttpRedirect"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:IIS-HttpRedirect"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part8"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: IIS-ApplicationDevelopment"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:IIS-ApplicationDevelopment"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part10"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: IIS-NetFxExtensibility"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:IIS-NetFxExtensibility"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part12"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: IIS-ISAPIExtensions"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:IIS-ISAPIExtensions"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part11"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: IIS-ASP"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:IIS-ASP"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part13"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: IIS-ISAPIFilter"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:IIS-ISAPIFilter"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part9"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: IIS-ASPNET"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:IIS-ASPNET"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part14"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: IIS-HealthAndDiagnostics"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:IIS-HealthAndDiagnostics"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part15"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: IIS-HttpLogging"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:IIS-HttpLogging"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part16"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: IIS-LoggingLibraries"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:IIS-LoggingLibraries"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part17"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: IIS-RequestMonitor"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:IIS-RequestMonitor"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part18"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: IIS-HttpTracing"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:IIS-HttpTracing"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part19"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: IIS-CustomLogging"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:IIS-CustomLogging"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part20"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: IIS-Security"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:IIS-Security"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part21"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: IIS-WindowsAuthentication"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:IIS-WindowsAuthentication"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part22"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: IIS-RequestFiltering"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:IIS-RequestFiltering"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part23"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: IIS-IPSecurity"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:IIS-IPSecurity"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part24"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: IIS-Performance"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:IIS-Performance"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part25"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: IIS-HttpCompressionStatic"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:IIS-HttpCompressionStatic"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part26"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: IIS-WebServerManagementTools"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:IIS-WebServerManagementTools"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part27"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: IIS-ManagementConsole"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:IIS-ManagementConsole"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part28"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: IIS-ManagementScriptingTools"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:IIS-ManagementScriptingTools"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part29"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: IIS-ManagementService"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:IIS-ManagementService"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part30"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: WAS-WindowsActivationService"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:WAS-WindowsActivationService"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part31"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: WAS-ProcessModel"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:WAS-ProcessModel"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part32"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: WAS-NetFxEnvironment"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:WAS-NetFxEnvironment"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part33"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: WAS-ConfigurationAPI"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:WAS-ConfigurationAPI"
                  >
      </ExePackage>
      <ExePackage
                  Id="IIS_part34"
                  SourceFile="run.bat"
                  DisplayName="Installing IIS: NetFx3"
                  InstallCommand="dism.exe /Online /Enable-Feature /FeatureName:NetFx3"
                  >
      </ExePackage>
    </PackageGroup>
  </Fragment>
</Wix>

The run.bat file is a simple text file, containing %*.

This solution only works on Windows 7, or higher, 'cause the dism.exe is not part of the Windows before version 7.

Community
  • 1
  • 1
Nagy Vilmos
  • 1,878
  • 22
  • 46
  • Not sure if there is a better way, but for me I had to replace 'dism.exe' with 'C:\WINDOWS\SYSNATIVE\DISM.EXE' (appeared to be using 32bit when it should have been using 64bit? possibly my bootstrapper isn't running the correct version? – Josh Mc Nov 13 '17 at 23:28
  • I think you can see the explanation here: https://stackoverflow.com/a/26422001/2891426 – Nagy Vilmos Nov 14 '17 at 09:48
4

@Nagy Vilmos, your solution won't work on 64-bit OS. Burn is 32-bit program. It will launch the 32-bit "dism.exe", even if you want it to run the 64-bit dism by giving full path "C:\Windows\System32\dism.exe" on 64-bit OS. That is caused by "File System Redirector".

The dism's log will tell you it's 32-bit or 64-bit. Open file "C:\Windows\Logs\DISM\dism.log" you will find information like this:

Host machine information: OS Version=6.1.7600, Running architecture=x86

Or,

Host machine information: OS Version=6.1.7600, Running architecture=amd64

When you try to run the 32-bit dism on and 64-bit OS, you will get this error

Error: 11 You cannot service a running 64-bit operating system with a 32-bit version of DI SM. Please use the version of DISM that corresponds to your computer's architecture. The DISM log file can be found at C:\Windows\Logs\DISM\dism.log

My solution is creating another WiX installer project "InstallPrerequisites" and run the 64-bit dism with "QtExec64CmdLine" . Here is an example:

<!--1.You need to use the x64 version of quiet command line     
    2.[System64Folder] is also needed. If not, QtExec64CmdLine will find a 32-bit dism.exe to run.
-->
<Property Id="QtExec64CmdLine" Value='"[System64Folder]dism.exe" /Online /Apply-Unattend:[ProductTmpFolder]iis_unattend.xml'/>
<CustomAction Id="SilentLaunch" BinaryKey="WixCA" DllEntry="CAQuietExec64" Execute="immediate" Return="check" />

I use answer file to include all the features, so we can enable them all at one time. And then chain the installer

<MsiPackage DisplayName="Install Prerequisites" SourceFile="$(var.InstallPrerequisites.TargetPath)" />

Update: By using "C:\windows\SysNative\dism.exe", I can now avoid a separate project for x64 platform. From the log, you can see the 32 bit process is now running 64-bit DISM.

2015-10-26 16:28:07, Info  DISM  DISM.EXE: <----- Starting Dism.exe session ----->
2015-10-26 16:28:07, Info  DISM  DISM.EXE: 
2015-10-26 16:28:07, Info  DISM  DISM.EXE: Host machine information: OS Version=6.1.7601, Running architecture=amd64, Number of processors=4
2015-10-26 16:28:07, Info  DISM  DISM.EXE: Executing command line: C:\windows\SysNative\dism.exe
2015-10-26 16:28:07, Info  DISM  DISM Provider Store: PID=2000 Getting the collection of providers from a local provider store type. - CDISMProviderStore::GetProviderCollection
....
2015-10-26 16:28:09, Info  DISM  DISM.EXE: Image session has been closed. Reboot required=no.
2015-10-26 16:28:09, Info  DISM  DISM.EXE: 
2015-10-26 16:28:09, Info  DISM  DISM.EXE: <----- Ending Dism.exe session ----->
Gustavo Mori
  • 8,319
  • 3
  • 38
  • 52
Rader
  • 188
  • 2
  • 6
  • 4
    To make it work on 64-bit OS, just call DISM as explained [here](http://stackoverflow.com/a/5936741/15186) to avoid redirection. –  Sep 09 '15 at 08:33
  • @omatrot it works, I have updated the answer. Thank you! – Rader Oct 26 '15 at 08:51
3

Try the following CustomAction Code:-

    <Property Id="INSTALLIISPROP" Value="C:\Windows\System32\dism.exe" />

    <CustomAction 
      Id="InstallIISCA"
      Return="check"
      Property="INSTALLIISPROP"
      Execute="deferred"
      HideTarget="yes"
      Impersonate="yes"
      ExeCommand="/Online /Enable-Feature /FeatureName:IIS-WebServerRole /FeatureName:IIS-WebServer /FeatureName:IIS-CommonHttpFeatures /FeatureName:IIS-StaticContent /FeatureName:IIS-DefaultDocument /FeatureName:IIS-DirectoryBrowsing /FeatureName:IIS-HttpErrors /FeatureName:IIS-HttpRedirect /FeatureName:IIS-ApplicationDevelopment /FeatureName:IIS-ASPNET /FeatureName:IIS-NetFxExtensibility /FeatureName:IIS-ASP /FeatureName:IIS-ISAPIExtensions /FeatureName:IIS-ISAPIFilter /FeatureName:IIS-HealthAndDiagnostics /FeatureName:IIS-HttpLogging /FeatureName:IIS-LoggingLibraries /FeatureName:IIS-RequestMonitor /FeatureName:IIS-HttpTracing /FeatureName:IIS-CustomLogging     /FeatureName:IIS-Security /FeatureName:IIS-WindowsAuthentication /FeatureName:IIS-RequestFiltering /FeatureName:IIS-IPSecurity /FeatureName:IIS-Performance /FeatureName:IIS-HttpCompressionStatic     /FeatureName:IIS-WebServerManagementTools /FeatureName:IIS-ManagementConsole /FeatureName:IIS-ManagementScriptingTools /FeatureName:IIS-ManagementService /FeatureName:WAS-WindowsActivationService /FeatureName:WAS-ProcessModel /FeatureName:WAS-NetFxEnvironment /FeatureName:WAS-ConfigurationAPI /FeatureName:NetFx3" />

    <InstallExecuteSequence>
       <Custom Action="InstallIISCA" Before="InstallFinalize">
          <![CDATA[NOT Installed AND IISMAJORVERSION]]>
       </Custom>
    </InstallExecuteSequence> 
Eternal21
  • 4,190
  • 2
  • 48
  • 63
  • Where should I put this CustomAction code? Inside the Chain tag? Or? – Nagy Vilmos Jun 30 '14 at 22:07
  • 1
    This Needs to sit under Product tag in your Product.Wxs file. – Harbinder Singh Jul 01 '14 at 08:38
  • Yep, but I'd like to put the IIS Installer into the burn package, not the .msi file. (My Burn package contains the installer of SQLExpress, .NET, IIS, and my project's .msi installer). But thanks for the dism.exe file and its commands, I think I solved the problem with it. – Nagy Vilmos Jul 01 '14 at 12:21
  • 1
    Note that the execommand text here is not formatted correctly - the enable feature command needs to be either `/online /enable-feature:IIS-WebserverRole` or `/online /enable-feature /featurename:IIS-WebserverRole /featurename:`note that there is no semi colons – Void Oct 27 '14 at 10:45
  • i wanted to enable asp.net 4.5 feature in iis. how can i do that – Prashant Kumar May 05 '17 at 09:11
  • 1
    If you're planning to use IIS only as reverse proxy for Asp.NET Core Kestrel, then you only need the following 3 features: /FeatureName:IIS-WebServerManagementTools /FeatureName:IIS-WebServerRole /FeatureName:IIS-ManagementConsole – Eternal21 Oct 24 '17 at 15:18
1

IIS feature enabling works for me.

<!-- Put the following Code inside Product tag -->
<UI>
  <UIRef Id="WixUI_HK" />
    <ProgressText Action="InstallIIS">Enabling IIS Feature</ProgressText> 
</UI>

<!-- Use DISM to setup IIS (see also http://support.microsoft.com/kb/2736284) -->
<!-- Build path to dism.exe (full path is important, just calling dism.exe without path will fail) -->
<CustomAction Id="InstallIISSetProperty" Property="InstallIIS" Execute="immediate"
                  Value="&quot;[System64Folder]dism.exe&quot; /Online /Enable-Feature /All /FeatureName:IIS-WebServerRole /FeatureName:IIS-WebServer /FeatureName:IIS-ManagementConsole " />
<!-- Call dism.exe quietly (without showing command prompt).
(see also http://wixtoolset.org/documentation/manual/v3/customactions/qtexec.html) -->
<CustomAction Id="InstallIIS" BinaryKey="WixCA" DllEntry="CAQuietExec64"
                Execute="deferred" HideTarget="no" Return="ignore" Impersonate="no"/>

<InstallExecuteSequence>         
  <Custom Action="InstallIISSetProperty" After="CostFinalize">
    <![CDATA[NOT Installed AND NOT IISMAJORVERSION]]>
  </Custom>
  <Custom Action="InstallIIS" Before="WriteRegistryValues">
    <![CDATA[NOT Installed AND NOT IISMAJORVERSION]]>
  </Custom>
</InstallExecuteSequence>

Reference Link

Mahesh
  • 97
  • 8
0

Here is some WIX code for quick fix

run64.bat: I wonder why it requires both lines to trick the File System Redirector

set "SystemPath=%windir%\Sysnative"
CD "%windir%\Sysnative""
%*

InstallIIS.wxs: replace run.bat for platform specific batch

  <?if $(var.Platform) = x86 ?> 
  <?define PlatformRunBatch = "run.bat" ?> 
  <?else?> 
  <?define PlatformRunBatch = "run64.bat" ?> 
  <?endif?> 
  <ExePackage Id="IIS_part0"
              SourceFile="$(var.PlatformRunBatch)"
Davi Fiamenghi
  • 1,237
  • 12
  • 28