Wix & Burn-如果尚未安装,请安装IIS

6

我有一个使用IIS的项目,想要使用Wix创建一个安装程序。我已经成功创建了应用程序的.msi安装程序,现在正在为它创建一个Bundle安装程序,它将安装必备组件,然后再安装我的应用程序。

以下是Bundle的代码:

<?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>

我的问题是,如果没有安装,我该如何安装(或启用)IIS?谢谢!
5个回答

14

根据Harbinder Singh答案,这里是我的解决方案:

<?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>

run.bat文件是一个简单的文本文件,包含%*

这个解决方案仅适用于Windows 7及以上版本,因为dism.exe不属于Windows 7之前的任何版本。


不确定是否有更好的方法,但对我来说,我必须用'C:\WINDOWS\SYSNATIVE\DISM.EXE'替换'dism.exe'(似乎在使用32位时应该使用64位?可能我的引导程序没有运行正确的版本?)。 - Josh Mc
我认为你可以在这里看到解释:https://dev59.com/tYHba4cB1Zd3GeqPLQHx#26422001 - Nagy Vilmos

4

@Nagy Vilmos,你提供的解决方案无法在64位操作系统上运行。 Burn是一个32位程序,即使您想通过完整路径“C:\Windows\System32\dism.exe”在64位操作系统上运行64位dism,它也会启动32位的“dism.exe”。这是由于“文件系统重定向器”导致的。

dism的日志将告诉您它是32位还是64位。打开文件“C:\Windows\Logs\DISM\dism.log”,您将找到以下信息:

主机机器信息:OS版本=6.1.7600,运行架构=x86

或者,

主机机器信息:OS版本=6.1.7600,运行架构=amd64

当您尝试在64位操作系统上运行32位dism时,您将收到以下错误:

错误:11 您不能使用32位版本的DISM服务于正在运行的64位操作系统。 请使用与计算机架构相对应的DISM版本。 DISM日志文件可以在C:\Windows\Logs\DISM\dism.log中找到

我的解决方案是创建另一个WiX安装程序项目“InstallPrerequisites”,并使用“QtExec64CmdLine”运行64位dism。以下是一个示例:

<!--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" />

我使用答案文件来包含所有功能,这样我们就可以一次性启用它们。然后链接安装程序。

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

更新: 通过使用"C:\windows\SysNative\dism.exe",我现在可以避免为x64平台创建单独的项目。从日志中,您可以看到32位进程现在正在运行64位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 ----->

4
要使其在 64 位操作系统上运行,请按照这里的说明调用 DISM,以避免重定向。 - anon
@omatrot 它可以工作了,我已经更新了答案。谢谢! - Rader

3
尝试以下自定义操作代码:-
    <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> 

我应该把这个CustomAction代码放在哪里?在Chain标签内部吗?还是其他地方? - Nagy Vilmos
1
这需要放在你的Product.Wxs文件中的Product标签下方。 - Harbinder Singh
是的,但我想把IIS安装程序放入burn包中,而不是.msi文件。(我的Burn包含SQLExpress、.NET、IIS和我的项目的.msi安装程序)。但感谢提供dism.exe文件及其命令,我认为我已经用它解决了问题。 - Nagy Vilmos
1
请注意,此处的execommand文本格式不正确 - 启用功能命令需要是/online /enable-feature:IIS-WebserverRole/online /enable-feature /featurename:IIS-WebserverRole /featurename:<features name>。请注意,没有分号。 - Void
我想在IIS中启用ASP.NET 4.5功能。我该怎么做? - Prashant Kumar
1
如果您计划将IIS仅用作Asp.NET Core Kestrel的反向代理,则只需要以下3个功能:/FeatureName:IIS-WebServerManagementTools /FeatureName:IIS-WebServerRole /FeatureName:IIS-ManagementConsole。 - Eternal21

1

IIS功能启用对我来说有效。

<!-- 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>

参考链接


0

这里是一些WIX代码,用于快速修复

run64.bat:我想知道为什么需要这两行来欺骗文件系统重定向器

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

InstallIIS.wxs:替换特定平台批处理的 run.bat

  <?if $(var.Platform) = x86 ?> 
  <?define PlatformRunBatch = "run.bat" ?> 
  <?else?> 
  <?define PlatformRunBatch = "run64.bat" ?> 
  <?endif?> 
  <ExePackage Id="IIS_part0"
              SourceFile="$(var.PlatformRunBatch)"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接