代码之家  ›  专栏  ›  技术社区  ›  Grant

如何在WiX中创建条件属性?(几乎就像If Then)

  •  4
  • Grant  · 技术社区  · 17 年前

    我有一个安装了一些EXE文件的WiX项目。一个是“主”可执行文件,其他是帮助诊断问题的支持程序。

    主可执行文件是可选的,支持程序将自行运行。通常,最终用户会安装第三方程序,而不是我的主可执行文件。

    在WiX安装程序结束时,我想有一个“启动程序”复选框,一旦安装程序关闭,它就会运行程序。

    我可以根据INSTALLLEVEL属性隐藏复选框,但这仅取决于用户是选择了“典型”还是“完成”安装。我想根据是否安装了主要的可执行功能来隐藏它。

    这样的东西是理想的:

    <Feature Id='MainProgram' Title='MainExe'
             Description='This application stores and displays information from our hardware.'
             ConfigurableDirectory='INSTALLDIR' Level='4'
             AllowAdvertise='no'>
        <ComponentRef Id='MainExecutable' />
        <ComponentRef Id='SQLLibrary' />
        <ComponentRef Id='ProgramIcon' />
        <ComponentRef Id='RemovePluginsFolder'/>
        <Property Id='ShowFinalCheckbox'>1</Property> #<--This won't work, but I'd like it to.
    </Feature>
    
    3 回复  |  直到 13 年前
        1
  •  10
  •   Duncan Smart    14 年前

    SetProperty元素可用于在操作之前或之后更改Property的值。要根据可执行文件的安装状态设置值,我将使用文档中记录的组件状态的组合 Conditional Statement Syntax in MSI SDK 。你得试试这个例子,但我认为这会让你接近目标。

    <SetProperty Id="ShowFinalCheckBox" Value="1" After="CostFinalize">?MainExecutableComponent&gt;2 OR $MainExecutableComponent&gt;2</SetProperty>
    

    上面的MSI SDK链接中解释了其中的所有魔法。

        2
  •  1
  •   Peter Mortensen Pieter Jan Bonestroo    10 年前

    对于WiX 2,您可以使用&功能,以了解是否安装了该功能:

    <Dialog Id="ExitDlg" Width="370" Height="270" Title="[ProductName] [Setup]" NoMinimize="yes">
        <Control Id="Finish" Type="PushButton" X="236" Y="243" Width="56" Height="17"
                 Default="yes" Cancel="yes" Text="Finish">
          <Publish Event="EndDialog" Value="Return">1</Publish>
          <Publish Event="DoAction" Value="LaunchFile">(NOT Installed) AND (LAUNCHPRODUCT = 1) AND (&amp;MainExecutable = 3)</Publish>
        </Control>
        <Control Id="Cancel" Type="PushButton" X="304" Y="243" Width="56" Height="17" Disabled="yes" Text="Cancel" />
        <Control Id="Bitmap" Type="Bitmap" X="0" Y="0" Width="370" Height="234" TabSkip="no" Text="[DialogBitmap]" />
        <Control Id="Back" Type="PushButton" X="180" Y="243" Width="56" Height="17" Disabled="yes" Text="Back" />
        <Control Id="Description" Type="Text" X="135" Y="70" Width="220" Height="20" Transparent="yes" NoPrefix="yes">
          <Text>Click the Finish button to exit the Wizard.</Text>
        </Control>
        <Control Id="BottomLine" Type="Line" X="0" Y="234" Width="370" Height="0" />
        <Control Id="Title" Type="Text" X="135" Y="20" Width="220" Height="60" Transparent="yes" NoPrefix="yes">
          <Text>{\VerdanaBold13}Completing the [ProductName] Wizard</Text>
        </Control>
        <Control Id="Launch" Type="CheckBox" X="135" Y="120" Width="150" Height="17"
                 Property="LAUNCHPRODUCT" CheckBoxValue="1">
          <Text>Launch [ProductName]</Text>
          <Condition Action="hide">
            NOT (&amp;MainProgramFeature = 3)
          </Condition>
        </Control>
      </Dialog>
    

    这样,您可以隐藏对话框,并使用相同的条件不启动程序(无论复选框的初始状态如何)。

        3
  •  0
  •   Peter Mortensen Pieter Jan Bonestroo    13 年前

    手册中对此进行了详细记录, How To: Run the Installed Application After Setup .

    推荐文章