【问题标题】:WiX Extended Bootstrapper Application: How to determine which radio button is selected?WiX 扩展引导程序应用程序:如何确定选择了哪个单选按钮?
【发布时间】:2013-02-07 00:39:40
【问题描述】:

这是我的设置:

所以我正在创建一个引导程序安装项目,虽然我已经让它工作了,但我觉得有一种更干净、更简单的方法可以做到这一点。

基本上,我需要让用户在安装产品时选择他们希望使用的环境。为此,我使用WiX Extended Bootstrapper Application extension 允许我在第一个安装屏幕上放置一些单选按钮。

进行所有设置都很好,但后来我意识到我不知道如何轻松确定选择了哪个单选按钮。因此,当我解决问题时,我只是在捆绑包中列出了 MSI 三次,并在每一次上都设置了安装条件。

有没有一种方法可以确定仅使用一个属性选择了哪个单选按钮?(例如,当我将 InstallFolder 属性传递给我的 MSI 时,如代码所示下面。)如果目前没有办法做到这一点,有没有办法让我在不将我的 MSI 三次添加到捆绑包中的情况下做到这一点?

这是我的代码(请注意我如何将基本相同的MsiPackage 列出三遍):

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
     xmlns:bal="http://schemas.microsoft.com/wix/BalExtension"
     xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
  <?include Properties.wxi ?>

  <Bundle Name="!(loc.Product.Name)" Version="$(var.Version)" Manufacturer="!(loc.Product.Manufacturer)" UpgradeCode="$(var.UpgradeCode)" Condition="VersionNT >= v5.1">
    <BootstrapperApplicationRef Id="WixExtendedBootstrapperApplication.Hyperlink2License">
      <bal:WixExtendedBootstrapperApplication SuppressRepair="yes" LicenseUrl="" ThemeFile="$(var.Bundle.ExtTheme.RadioBtns.Path)" LocalizationFile="$(var.Bundle.ExtTheme.RadioBtns.l10n.Path)" />
    </BootstrapperApplicationRef>

    <WixVariable Id="WixMbaPrereqPackageId" Value="Netfx4Full" />

    <Variable Name="InstallFolder" Type="string" Value="$(var.InstallFolder.Value)" />

    <Variable Name="RadioButton1" Type="numeric" Value="0" />
    <Variable Name="RadioButton2" Type="numeric" Value="0" />
    <Variable Name="RadioButton3" Type="numeric" Value="1" />

    <Chain>
      <!-- Other Package References Here -->

      <MsiPackage Id="DBConnections_Dev"
                  SourceFile="$(var.MSI.Path)"
                  Visible="no"
                  Vital="yes"
                  InstallCondition="RadioButton1 = 1">
        <MsiProperty Name="INSTALLFOLDER" Value="[InstallFolder]" />
        <MsiProperty Name="SELECTED_ENV" Value="1" />
      </MsiPackage>
      <MsiPackage Id="DBConnections_Stage"
                  SourceFile="$(var.MSI.Path)"
                  Visible="no"
                  Vital="yes"
                  InstallCondition="RadioButton2 = 1">
        <MsiProperty Name="INSTALLFOLDER" Value="[InstallFolder]" />
        <MsiProperty Name="SELECTED_ENV" Value="2" />
      </MsiPackage>
      <MsiPackage Id="DBConnections_Prod"
                  SourceFile="$(var.MSI.Path)"
                  Visible="no"
                  Vital="yes"
                  InstallCondition="RadioButton3 = 1">
        <MsiProperty Name="INSTALLFOLDER" Value="[InstallFolder]" />
        <MsiProperty Name="SELECTED_ENV" Value="3" />
      </MsiPackage>
    </Chain>
  </Bundle>
</Wix>

【问题讨论】:

    标签: wix bootstrapper


    【解决方案1】:

    我也在项目的 CodePlex 网站上问过这个问题,开发者回复如下(这里是完整讨论的链接:http://wixextba.codeplex.com/discussions/432341):

    This can now be done using the custom actions feature.

    我测试了他的回答,发现它是正确的!此功能自版本 3.7.4791.32058 起可用。 source code 中还包含一个示例,演示了这是如何完成的。我在下面发布了相关代码:

    Custom Action c++ 代码中需要:

    STDMETHODIMP OnPlanCustomAction()
    {
      ...
      if (SUCCEEDED(BalGetNumericVariable(L"RadioButton1", &llValue)) && llValue)
      {
        m_pEngine->SetVariableNumeric(L"RadioButton", 1);
        BalExitOnFailure(hr, "Failed to set variable.");
      }
      else if (SUCCEEDED(BalGetNumericVariable(L"RadioButton2", &llValue)) && llValue)
      {
        m_pEngine->SetVariableNumeric(L"RadioButton", 2);
        BalExitOnFailure(hr, "Failed to set variable.");
      }
      else if (SUCCEEDED(BalGetNumericVariable(L"RadioButton3", &llValue)) && llValue)
      {
        m_pEngine->SetVariableNumeric(L"RadioButton", 3);
        BalExitOnFailure(hr, "Failed to set variable.");
      }
      else if (SUCCEEDED(BalGetNumericVariable(L"RadioButton4", &llValue)) && llValue)
      {
        m_pEngine->SetVariableNumeric(L"RadioButton", 4);
        BalExitOnFailure(hr, "Failed to set variable.");
      }
      else
      {
        m_pEngine->SetVariableNumeric(L"RadioButton", 0);
        BalExitOnFailure(hr, "Failed to set variable.");
      }
      ...
    


    WiX XML 中需要(来自examples that come with downloaded DLL):

    <Variable Name="RadioButton1" Type="numeric" Value="0" />
    <Variable Name="RadioButton2" Type="numeric" Value="1" />
    <Variable Name="RadioButton3" Type="numeric" Value="0" />
    <Variable Name="RadioButton4" Type="numeric" Value="0" />
    
    <Chain DisableSystemRestore="yes">
      <PackageGroupRef Id="NetFx40Redist" />
      <MsiPackage
        Id="Setup"
        Compressed="yes"
        SourceFile="Setup.msi"
        Vital="yes">
        <MsiProperty Name="APPLICATIONFOLDER" Value="[InstallFolder]" />
        <MsiProperty Name="RadioButton" Value="[RadioButton]" />
      </MsiPackage>
    </Chain>
    

    查看文本中的链接以获取这些代码示例的原始示例。希望这对将来的其他人有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-05
      • 2020-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-13
      • 2015-09-11
      • 2019-09-23
      相关资源
      最近更新 更多