根据复选框安装功能

时间:2012-02-20 20:04:38

标签: c# wix wix3.5

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

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

3 个答案:

答案 0 :(得分:7)

我发现它解决了我的问题。为了按照我的意图去做,我需要为每个单独的功能创建一个复选框。

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

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

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

注意:

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

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

ADDLOCAL=FeatureX,FeatureY,FeatureZ...

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

 <ComponentGroupRef Id="FeatureX"/>

所以它就是......我再次感谢大家对此的帮助。如果任何读这篇文章的人都被任何事情搞糊涂了,请随时给我留言,我会尽力解释一下。

答案 1 :(得分:0)

复选框的建议与radio buttons的建议非常类似。在“下一个”或“安装”按钮上使用AddLocal和Remove控件事件,每个按钮都绑定到与复选框关联的属性。在向用户显示UI时使用功能安装级别为时已晚。

答案 2 :(得分:0)

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

Product.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>

UserInterface.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

的基本安装程序
相关问题