使用 WIX 安装程序安装 .NET Framework 4.7.2(如果需要)

Install .NET Framework 4.7.2 (if needed) with WIX installer

求助! 我继承了一个带有 WIX 安装程序项目的 .NET 项目。他们隐含地假设每台机器上都安装了 .NET Framework 4.5,这在很大程度上是正确的。现在我们正在添加一些需要 .NET Framework 4.7.2 的功能。我想修改安装集以检查是否存在 4.7.2(或更高版本)并在必要时通过网络安装。我发现一些文档部分回答了我的问题,但我仍然很困惑如何开始以及如何填写细节。是否有任何完整的演示或说明可用?我的理解是我需要添加一个 "BootStrapper" 项目。如果我然后 add/reference 来自我的主要安装(我现有的安装)的 BootStrapper 项目,或者如果我将主要安装引用为 Bootstrapper 项目的一部分(通过 MsiPackage 元素),我会感到困惑。另外,我该如何设置以检查 4.7.2?我找到的所有参考资料都是针对 4.5 或更早版本的,显然注册表中用于检查的位置已更改:

How do I detect what .NET Framework versions and service packs are installed?

假设我在 Bootstrapper 中引用我的主要安装,我该怎么做?

这些是我为感兴趣的人找到的链接。他们都暗示了答案,但没有给出完整的答案 and/or 已经过时了。

http://wixtoolset.org/documentation/manual/v3/howtos/redistributables_and_install_checks/install_dotnet.html

https://www.firegiant.com/wix/tutorial/net-and-net/bootstrapping/

https://wix.ronifuchs.com/

最后,我相信我正在使用 WIX Toolset v3.11。这是文件夹指示的内容 (C:\Program Files (x86)\WiX Toolset v3.11)

我提到这个是因为一些参考资料提到了 Wix 4.0(示例:http://wixtoolset.org/releases/" />)

谢谢!

去年 here 开了一张工单,并提供了解决方法:

  <?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. -->

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">

  <!--
        .NET Framework installation state properties

        Official documentation can be found at the following location:

           .NET Framework 4.5/4.5.1/4.5.2/4.6/4.6.1/4.6.2/4.7/4.7.1 - http://msdn.microsoft.com/en-us/library/w0x726c2(v=vs.110).aspx
    -->

  <?define NetFx471MinRelease = 461308 ?>
  <?define NetFx471WebLink = http://go.microsoft.com/fwlink/?LinkId=852092 ?>
  <?define NetFx471RedistLink = http://go.microsoft.com/fwlink/?LinkId=852104 ?>
  <?define NetFx471EulaLink = http://referencesource.microsoft.com/license.html ?>

  <Fragment>
    <PropertyRef Id="WIXNETFX4RELEASEINSTALLED" />
    <Property Id="WIX_IS_NETFRAMEWORK_471_OR_LATER_INSTALLED" Secure="yes" />
    <SetProperty Id="WIX_IS_NETFRAMEWORK_471_OR_LATER_INSTALLED" Value="1" After="AppSearch">
      WIXNETFX4RELEASEINSTALLED >= "#$(var.NetFx471MinRelease)"
    </SetProperty>
  </Fragment>

  <Fragment>
    <util:RegistrySearchRef Id="NETFRAMEWORK45"/>

    <WixVariable Id="WixMbaPrereqPackageId" Value="NetFx471Web" />
    <WixVariable Id="WixMbaPrereqLicenseUrl" Value="$(var.NetFx471EulaLink)" Overridable="yes" />
    <WixVariable Id="NetFx471WebDetectCondition" Value="NETFRAMEWORK45 &gt;= $(var.NetFx471MinRelease)" Overridable="yes" />
    <WixVariable Id="NetFx471WebInstallCondition" Value="" Overridable="yes" />
    <WixVariable Id="NetFx471WebPackageDirectory" Value="redist\" Overridable="yes" />

    <PackageGroup Id="NetFx471Web">
      <ExePackage
          InstallCommand="/q /norestart /ChainingPackage &quot;[WixBundleName]&quot; /log &quot;[NetFx471FullLog].html&quot;"
          RepairCommand="/q /norestart /repair /ChainingPackage &quot;[WixBundleName]&quot; /log &quot;[NetFx471FullLog].html&quot;"
          UninstallCommand="/uninstall /q /norestart /ChainingPackage &quot;[WixBundleName]&quot; /log &quot;[NetFx471FullLog].html&quot;"
          PerMachine="yes"
          DetectCondition="!(wix.NetFx471WebDetectCondition)"
          InstallCondition="!(wix.NetFx471WebInstallCondition)"
          Id="NetFx471Web"
          Vital="yes"
          Permanent="yes"
          Protocol="netfx4"
          DownloadUrl="$(var.NetFx471WebLink)"
          LogPathVariable="NetFx471FullLog"
          Compressed="no"
          Name="!(wix.NetFx471WebPackageDirectory)NDP471-KB4033344-Web.exe">
        <RemotePayload
          CertificatePublicKey="2ECAEC21B884B40A7C5FB141D2CBC4CDA4930752"
          CertificateThumbprint="49D59D86505D82942A076388693F4FB7B21254EE"
          Description="Microsoft .NET Framework 4.7.1 Setup"
          Hash="C0919415622D86C3D6AB19F0F92EA938788DB847"
          ProductName="Microsoft .NET Framework 4.7.1"
          Size="1434504"
          Version="4.7.2558.0" />
      </ExePackage>
    </PackageGroup>
  </Fragment>

  <Fragment>
    <util:RegistrySearchRef Id="NETFRAMEWORK45"/>

    <WixVariable Id="WixMbaPrereqPackageId" Value="NetFx471Redist" />
    <WixVariable Id="WixMbaPrereqLicenseUrl" Value="$(var.NetFx471EulaLink)" Overridable="yes" />
    <WixVariable Id="NetFx471RedistDetectCondition" Value="NETFRAMEWORK45 &gt;= $(var.NetFx471MinRelease)" Overridable="yes" />
    <WixVariable Id="NetFx471RedistInstallCondition" Value="" Overridable="yes" />
    <WixVariable Id="NetFx471RedistPackageDirectory" Value="redist\" Overridable="yes" />

    <PackageGroup Id="NetFx471Redist">
      <ExePackage
          InstallCommand="/q /norestart /ChainingPackage &quot;[WixBundleName]&quot; /log &quot;[NetFx471FullLog].html&quot;"
          RepairCommand="/q /norestart /repair /ChainingPackage &quot;[WixBundleName]&quot; /log &quot;[NetFx471FullLog].html&quot;"
          UninstallCommand="/uninstall /q /norestart /ChainingPackage &quot;[WixBundleName]&quot; /log &quot;[NetFx471FullLog].html&quot;"
          PerMachine="yes"
          DetectCondition="!(wix.NetFx471RedistDetectCondition)"
          InstallCondition="!(wix.NetFx471RedistInstallCondition)"
          Id="NetFx471Redist"
          Vital="yes"
          Permanent="yes"
          Protocol="netfx4"
          DownloadUrl="$(var.NetFx471RedistLink)"
          LogPathVariable="NetFx471FullLog"
          Compressed="no"
          Name="!(wix.NetFx471RedistPackageDirectory)NDP471-KB4033342-x86-x64-AllOS-ENU.exe">
        <RemotePayload
          CertificatePublicKey="2ECAEC21B884B40A7C5FB141D2CBC4CDA4930752"
          CertificateThumbprint="49D59D86505D82942A076388693F4FB7B21254EE"
          Description="Microsoft .NET Framework 4.7.1 Setup"
          Hash="5F0597CEADDBDF3BAD24CA6EBE142BD81C2DF713"
          ProductName="Microsoft .NET Framework 4.7.1"
          Size="68742112"
          Version="4.7.2558.0" />
      </ExePackage>
    </PackageGroup>
  </Fragment>
</Wix>

然后在 bundle.wxs 中您需要添加:

  <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">

  <Bundle Name="..."
          Version="..." 
          Manufacturer="..." 
          UpgradeCode="..." 
          >

    <Chain>      

      <!--Install .Net Framework 4.7.1-->
      <PackageGroupRef Id="NetFx471Redist"/>

      <!--Install Product-->
      <MsiPackage
        Id="Setup"   
        DisplayInternalUI="yes"
        Compressed="yes"
        SourceFile="..."
        Vital="yes">        
      </MsiPackage>     

    </Chain>
  </Bundle>  
</Wix>

我发现这个问题是关于 4.7.2 的,但公认的答案是关于 4.7.1 版本,这有点误导人。

所有精确位都是here

刚刚在未安装 4.7.2 的计算机上进行测试,一切正常 - 安装程序下载并安装了 .NET Framework 组件,然后它继续安装程序本身。