【问题标题】:Install features based on checkboxes基于复选框安装功能
【发布时间】:2023-04-01 13:25:01
【问题描述】:

我正在尝试使当用户通过复选框选择某些内容时,将安装相应的功能。

我知道 Wix 提供的预建功能树,但我正在做的其他一些事情不允许我使用此功能。我很好奇如何将两者链接在一起,以便当用户选中“安装功能 X”复选框时,当用户单击安装按钮时会安装功能 X。

【问题讨论】:

  • 我将每个功能的所有级别设置为 0,当用户选中复选框并单击下一步时,我尝试使用“Addlocal”属性将级别设置为 1。但是除此之外,我很难找到替代解决方案。大多数人只是恢复到特征树
  • 属性名称为ADDLOCAL,全部大写。
  • 所以我将“AddLocal”更改为“ADDLOCAL”,但并没有解决问题。我想知道我是否可能遗漏了什么,也许我需要一个属性,当我选择复选框时,它会设置该值并从那里按条件安装...

标签: c# wix wix3.5


【解决方案1】:

我找到了解决我问题的方法。要按照我的预期做,我需要为每个功能创建一个复选框。

<Control Id="FeatureX" Type="CheckBox" X="191" Y="50" Width="140" Height="17"
     Property="FEATUREX_CHECKED" CheckBoxValue="myValue" Text="Install feature X" />
<Control Id="FeatureY" Type="CheckBox" X="191" Y="67" Width="140" Height="17"
     Property="FEATUREY_CHECKED" CheckBoxValue="myValue" Text="Install feature Y" />
<Control Id="FeatureZ" Type="CheckBox" X="191" Y="84" Width="140" Height="17"
     Property="FEATUREZ_CHECKED" CheckBoxValue="myValue" Text="Install feature Z" />

现在,一旦我这样做了,我就为每个发布添加了一个相应的发布,并设置了一个条件,以便只有选中该复选框才会安装该功能。像这样:

<Control Id="Next" Type="PushButton" Text="Next" X="254" Y="243" Height="17" Width="56">
   <Publish Event="Remove" Value="ALL" Order="1">1</Publish>
   <Publish Event="AddLocal" Value="FeatureX" Order="2">
      <![CDATA[FEATUREX_CHECKED]]>
   </Publish>
</Control>

注意:

Remove 用于取消选择安装中的所有内容(我注意到一旦调用 UI,更改功能级别为时已晚)。

然后检查每个功能以查看“相应的复选框”是否已被选中,如果是,则将其添加到“AddLocal”属性中。 AddLocal 看起来像这样:

ADDLOCAL=FeatureX, FeatureY, FeatureZ...

我需要做的最后一件事是检查我的 main.wxs 以确保复选框中使用的 FeatureID 与使用的 ComponentGroupRefID 匹配:

 <ComponentGroupRef Id="FeatureX"/>

原来如此…… 我再次感谢大家对此的帮助。如果有人读到这篇文章有什么困惑,请随时给我留言,我会尽力进一步解释。

【讨论】:

  • 如果您想静默安装,这会导致问题。由于从未单击该按钮,因此不会删除任何内容,并且始终安装所有内容。我现在正在处理这个问题。
  • 仍在解决静默安装问题。有什么理由选择这种方法而不是&lt;Feature Id="Feature1" Level="0"&gt; &lt;ComponentGroupRef Id="Components"/&gt; &lt;Condition Level="1"&gt;TCP_CHECKBOX_RESULT = "tcp"&lt;/Condition&gt; &lt;/Feature&gt;
  • 只有一个下一步按钮吗?下一个按钮如何知道检查了哪个功能?我不确定我是如何知道要安装哪个东西的。
【解决方案2】:

这是我安装功能的示例代码

产品.wxs

<Product Id="{C9FD5DDE-2625-4E01-B415-8A734464F341}" 
       Name="!(wix.Product)" Language="1033" Version="1.0.0.0" 
       Manufacturer="!(wix.Manufacturer)" UpgradeCode="!(wix.UpgradeCode)">


    <Package InstallerVersion="200" Compressed="yes" Languages="1033"
         Manufacturer="!(wix.Manufacturer)" Description="!(wix.ProductDesc)"/>

    <Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />

<WixVariable Id="UpgradeCode" Value="{E5695E2A-EE5F-4EEE-A326-98A9F8B2EF0A}"/>
<WixVariable Id="Manufacturer" Value="BSDreams"/>
<WixVariable Id="Product" Value="WixSubFeatures"/>
<WixVariable Id="ProductDesc" Value="Minimal select one feature install"/>
<WixVariable Id="ProductIcon" Value="chk_on.ico"/>
<WixVariable Id="WixSubFiles" Value=".\Files"/>

<Property Id="ARPNOMODIFY" Value="0" />
<Property Id="ARPPRODUCTICON" Value="!(wix.ProductIcon)" />

<Property Id="INSTALLDIR">
  <RegistrySearch Id="WixSubFeaturesSearch" Type="raw" Root="HKCU"
                  Key="!(wix.Manufacturer)\!(wix.Product)" Name="InstallDir" />
</Property>

<Icon Id="chk_on.ico" SourceFile="!(wix.WixSubFiles)\!(wix.ProductIcon)"/>

    <Directory Id="TARGETDIR" Name="SourceDir">
        <Directory Id="ManufacturerDir" Name="!(wix.Manufacturer)">
            <Directory Id="INSTALLDIR" Name="!(wix.Product)">

      <Component Id="ProductMain" Guid="{FF35C142-480A-4d67-A2ED-E5C9E508F809}">
        <CreateFolder />

        <RegistryKey Id="WixSubDirReg" Root="HKCU" Key="!(wix.Manufacturer)\!(wix.Product)" Action="createAndRemoveOnUninstall">
          <RegistryValue Type="string" Value="[INSTALLDIR]" Action="write"/>
        </RegistryKey>

      </Component>

            </Directory>
        </Directory>
    </Directory>

<UIRef Id="UserInterface"/>

    <Feature Id="PRODUCTFEATURE" Title="!(wix.Product)" Level="1" >
  <ComponentRef Id="ProductMain"/>
  <ComponentRef Id="IconFile"/>
  <Feature Id="OPTIONA" Title="Option A" Level="1" >
    <ComponentRef Id="TestFileA"/>
  </Feature>
  <Feature Id="OPTIONB" Title="Option B" Level="3" >
    <ComponentRef Id="TestFileB"/>
  </Feature>
  <Feature Id="OPTIONC" Title="Option C" Level="3" >
    <ComponentRef Id="TestFileC"/>
  </Feature>

</Feature>


<DirectoryRef Id="INSTALLDIR">
  <Component Id="IconFile" Guid="{967A5110-B0F8-47b0-967B-CC4624D06EA5}">
    <File Id="IconFileA" Source="!(wix.WixSubFiles)\!(wix.ProductIcon)" Name="chk_on.ico" Vital="yes" />
  </Component>

  <Component Id="TestFileA" Guid="{F5ACE3D7-03DE-47a7-9CE8-50CEF5E9A7BF}">
    <File Id="SomeFileA" Source="!(wix.WixSubFiles)\SomeFileA.txt" Name="BSDA.txt" Vital="yes"/>
  </Component>

  <Component Id="TestFileB" Guid="{CB5D53FB-8CED-42ef-89FF-08C7709CFCA5}">
    <File Id="SomeFileB" Source="!(wix.WixSubFiles)\SomeFileB.txt" Name="BSDB.txt" Vital="yes" />
  </Component>

  <Component Id="TestFileC" Guid="{987EA193-A1E0-41d2-8E9D-87D30D8F03AD}">
    <File Id="SomeFileC" Source="!(wix.WixSubFiles)\SomeFileC.txt" Name="BSDC.txt" Vital="yes" />
  </Component>

</DirectoryRef>

<CustomAction Id="SetARPINSTALLLOCATION" Property="ARPINSTALLLOCATION" Value="[INSTALLDIR]" />

<InstallExecuteSequence>
  <Custom Action="SetARPINSTALLLOCATION" After="InstallValidate"></Custom>
</InstallExecuteSequence>
</Product>

用户界面.wxs

<Fragment Id="WixSubUI">
<UI Id="UserInterface">
  <Property Id="WIXUI_INSTALLDIR" Value="INSTALLDIR" />
  <Property Id="WixUI_Mode" Value="Custom" />

  <TextStyle Id="WixUI_Font_Normal" FaceName="Tahoma" Size="8" />
  <TextStyle Id="WixUI_Font_Bigger" FaceName="Tahoma" Size="9" Bold="yes" />
  <TextStyle Id="WixUI_Font_Title"  FaceName="Tahoma" Size="9" Bold="yes" />

  <Property Id="DefaultUIFont" Value="WixUI_Font_Normal" />

  <DialogRef Id="ProgressDlg" />
  <DialogRef Id="ErrorDlg" />
  <DialogRef Id="FilesInUse" />
  <DialogRef Id="FatalError" />
  <DialogRef Id="UserExit" />
  <DialogRef Id="InstallDirDlg"/>
  <DialogRef Id="FeaturesDlg" />




  <Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="FeaturesDlg" Order="2"></Publish>

  <Publish Dialog="FeaturesDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg">1</Publish>

  <Publish Dialog="InstallDirDlg" Control="Back" Event="NewDialog" Value="FeaturesDlg">1</Publish>
  <Publish Dialog="InstallDirDlg" Control="ChangeFolder" Property="_BrowseProperty" Value="[WIXUI_INSTALLDIR]" Order="1">1</Publish>
  <Publish Dialog="InstallDirDlg" Control="ChangeFolder" Event="SpawnDialog" Value="BrowseDlg" Order="2">1</Publish>
  <Publish Dialog="InstallDirDlg" Control="Next" Event="SetTargetPath" Value="[WIXUI_INSTALLDIR]" Order="1">1</Publish>
  <Publish Dialog="InstallDirDlg" Control="Next" Event="NewDialog" Value="ExitDialog" Order="2">1</Publish>



  <Publish Dialog="ExitDialog" Control="Finish" Event="EndDialog" Value="Return" Order="999">1</Publish>

</UI>
<UIRef Id="WixUI_Common" />

这将为您提供一个基于所选功能复选框 UI 进行安装的基本安装程序

【讨论】:

    【解决方案3】:

    复选框的建议与radio buttons 的建议非常相似。在 Next 或 Install 按钮上使用 AddLocal 和 Remove 控件事件,每个事件都针对与复选框相关的属性。在您向用户显示 UI 时使用功能安装级别为时已晚。

    【讨论】:

    • 我明白了,为了做到这一点,我需要做这样的事情...... FEATUREX_CHECKEDNOT FEATUREX_CHECKED谢谢你的回复顺便说一句
    • 所以我尝试了几种不同的方法,但仍然没有用......还有其他可能会造成问题的想法吗?
    • @Jimmy,我有点困惑。在AddLocal属性中,值应该是Control的Id还是Feature的Id?您正在显示控件的 ID。另外,ComponentGroupRef Id 与 AddLocal 有什么关系?它实际上不应该是 Feature Id 吗?请帮忙。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    相关资源
    最近更新 更多