Wix工具集 - 基于TargetDir的条件安装

时间:2017-01-19 11:54:22

标签: installation wix conditional

我必须安装一个包含多个文件夹的应用程序。如果我的Targetdir不是默认路径,例如[ProgramFilesFolder]\[Manufacturer]\[ProductName],则可以在该Targetdir中安装所有文件夹。否则,有些文件夹,比如" Bin"和#34; AddIns",应该安装在不同的路径中,比如[CommonAppDataFolder]\[Manufacturer]\[ProductName]

我想避免使用C#或C ++自定义操作。相反,我会尝试使用Type51 CA.有可能吗?

我写了以下代码:

<Directory Id="TARGETDIR" Name="SourceDir">
  <Directory Id="CommonAppDataFolder">
    <Directory Id="dir_B1AA3D43_E9A6_4283_81B7_D24FDA02FEC4" Name="List SpA">
      <Component Id="comp_dir_B1AA3D43_E9A6_4283_81B7_D24FDA02FEC4" Guid="AB641867-3F7A-4A74-9923-03E71FC6851C" KeyPath="yes" Transitive="yes">
        <Condition><![CDATA[TARGETDIR = "[ProgramFilesFolder][Manufacturer]\[ProductName]"]]></Condition>
      </Component>
      <Directory Id="dir_9D19AF5A_89F2_498D_AC25_B48F2C16BFF5" Name="TestApplication">
        <Directory Id="dir_BinID2" Name="Bin">
          <Component Id="comp_dir_BinID2" Guid="2E369F78-D321-4828-A2A8-E958E57B910B" KeyPath="yes">
            <Condition><![CDATA[TARGETDIR = "[ProgramFilesFolder][Manufacturer]\[ProductName]"]]></Condition>
          </Component>
          <Component Id="comp_38B4C656_8291_4C45_98D5_A46908E33723" Guid="61DB01E5-6D6B-48AE-862A-3E2C18D546E7" Permanent="no" SharedDllRefCount="no" Transitive="no">
            <File Id="_14E547A6_A0C5_441E_A294_59AD578B99DF" DiskId="1" Hidden="no" ReadOnly="no" TrueType="no" System="no" Vital="yes" Name="TestApplication.exe" Source="..\Debug\TestApplication.exe" KeyPath="yes" />
          </Component>
        </Directory>
        <Directory Id="dir_AddInsID2" Name="AddIns">
          <Component Id="comp_dir_AddInsID2" Guid="0CA9B394-77E5-48A9-85A8-F6FF0737C499" KeyPath="yes" Transitive="yes">
            <Condition><![CDATA[TARGETDIR = "[ProgramFilesFolder][Manufacturer]\[ProductName]"]]></Condition>
          </Component>
          <Component Id="comp_6DCECE0A_AE42_49F1_BA42_B23EF2A50E44" Guid="216B87DA-4F28-4DC9-85AA-E3801E2C0A8B" Permanent="no" SharedDllRefCount="no" Transitive="no">
            <File Id="_D271147D_4984_4C55_9660_33F4617957F5" DiskId="1" Hidden="no" ReadOnly="no" TrueType="no" System="no" Vital="yes" Name="ClosePromptCA.CA.dll" Source="..\ClosePromptCA\bin\Debug\ClosePromptCA.CA.dll" KeyPath="yes" />
          </Component>
          <Component Id="comp_98FCDB58_9307_44D7_9CFE_3F1DB41BD779" Guid="B8368238-B1B6-4D78-BC21-0D26B84E4938" Permanent="no" SharedDllRefCount="no" Transitive="no">
            <File Id="_75368244_3285_47FD_BBC8_60CEC98755B4" DiskId="1" Hidden="no" ReadOnly="no" TrueType="no" System="no" Vital="yes" Name="Microsoft.Deployment.WindowsInstaller.dll" Source="..\ClosePromptCA\bin\Debug\Microsoft.Deployment.WindowsInstaller.dll" KeyPath="yes" />
          </Component>
        </Directory>
      </Directory>
    </Directory>
  </Directory>
  <Directory Id="dir_AddInsID" Name="AddIns">
    <Component Id="comp_dir_AddInsID" Guid="0219CA84-4787-4737-99E7-95ACD8E0846D" KeyPath="yes" Transitive="yes">
      <Condition><![CDATA[TARGETDIR <> "[ProgramFilesFolder][Manufacturer]\[ProductName]"]]></Condition>
    </Component>
    <Component Id="comp_23612F37_B27B_49E2_9FB6_9D2FA3654FB1" Guid="290915D5-38E9-4540-B7B7-7BBC27D96CA0" Permanent="no" SharedDllRefCount="no" Transitive="no">
      <File Id="_0193CC70_4486_4226_BE10_4F9C927DD5F2" DiskId="1" Hidden="no" ReadOnly="no" TrueType="no" System="no" Vital="yes" Name="ClosePromptCA.CA.dll" Source="..\ClosePromptCA\bin\Debug\ClosePromptCA.CA.dll" KeyPath="yes" />
    </Component>
    <Component Id="comp_41AA7508_C12C_46CC_A383_7088A8500898" Guid="5CACA050-A59C-44DF-BF5A-8694D547D937" Permanent="no" SharedDllRefCount="no" Transitive="no">
      <File Id="_362C000D_A631_4E5D_9288_FB623CD999E3" DiskId="1" Hidden="no" ReadOnly="no" TrueType="no" System="no" Vital="yes" Name="ClosePromptCA.XML" Source="..\ClosePromptCA\bin\Debug\ClosePromptCA.XML" KeyPath="yes" />
    </Component>
  </Directory>
  <Directory Id="dir_BinID" Name="Bin">
    <Component Id="comp_dir_BinID" Guid="99ADE113-162C-4299-8A3E-EDCE1FB838DE" KeyPath="yes" Transitive="yes">
      <Condition><![CDATA[TARGETDIR <> "[ProgramFilesFolder][Manufacturer]\[ProductName]"]]></Condition>
    </Component>
    <Component Id="comp_FD9AB046_9110_4BFD_865F_D919F02D7B2B" Guid="5690A672-809F-47D1-938E-EAC0E18A0685" Permanent="no" SharedDllRefCount="no" Transitive="no">
      <File Id="_89CFA2F5_2ED8_43C8_890E_A791BF9E16BB" DiskId="1" Hidden="no" ReadOnly="no" TrueType="no" System="no" Vital="yes" Name="TestApplication.exe" Source="..\Debug\TestApplication.exe" KeyPath="yes" />
    </Component>
  </Directory>
  <Directory Id="dir_DocsID" Name="Docs">
    <Component Id="comp_ECF1F68E_B9B8_49DD_9631_88E0722F8FCC" Guid="CB3861D1-6101-4F3C-94DD-AEE3EE74C217" Permanent="no" SharedDllRefCount="no" Transitive="no">
      <File Id="_9CE2FA29_27F8_4C00_B22D_A99AA59E5B2D" DiskId="1" Hidden="no" ReadOnly="no" TrueType="no" System="no" Vital="yes" Name="ReadMe.txt" Source="..\TestApplication\ReadMe.txt" KeyPath="yes" />
    </Component>
  </Directory>
  <Directory Id="dir_LogsID" Name="Logs">
    <Component Id="comp_B81BDCFD_B947_49C0_A07F_C1546D02E7AF" Guid="CE5206CE-E651-42C6-88AF-B7D83A9318C2" Permanent="no" SharedDllRefCount="no" Transitive="no">
      <File Id="_FF44C1E7_C235_47B9_BA01_C797D13EBA7D" DiskId="1" Hidden="no" ReadOnly="no" TrueType="no" System="no" Vital="yes" Name="trace.log" Source="bin\Debug\trace.log" KeyPath="yes" />
    </Component>
  </Directory>
  <Directory Id="dir_TemplateID" Name="Template">
    <Component Id="comp_8F946A00_3D1E_44C5_A288_E0662FFE253D" Guid="8C0A501B-15D4-46B1-91C3-23E5035CB145" Permanent="no" SharedDllRefCount="no" Transitive="no">
      <File Id="_39F2BD37_C7FE_4CF1_98C7_1E7BFC1B4873" DiskId="1" Hidden="no" ReadOnly="no" TrueType="no" System="no" Vital="yes" Name="ReadMe.txt" Source="..\..\CrashReportManager\ReadMe.txt" KeyPath="yes" />
    </Component>
  </Directory>
</Directory>

一切看起来都是正确的,但Wix忽略了条件。即使条件错误,Wix也会安装我的组件! 是什么原因?

2 个答案:

答案 0 :(得分:0)

您可以自动收集这两个位置,并将每个位置设置为不同的目录路径。

加热 - http://wixtoolset.org/documentation/manual/v3/msbuild/task_reference/heatdirectory.html

目录标志是收获目录。 DirectoryRefId是在目标计算机上部署的位置。

这是最常见的方法。

答案 1 :(得分:0)

您可以使用特殊文件夹ID来处理特殊文件夹,可以在msdn&#34; System Folder Properties&#34;找到可能的ID列表。

以下代码示例将向您展示案例的目录结构如何:

<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
    <Directory Id="MyProgramFilesFolder" Name="Manufacturer">
        <Directory Id="INSTALLLOCATION" Name="InstallLocation">
            <!-- Your "all the folders can be installed in that Targetdir"
            can be inserted here -->
        </Directory>
    </Directory>
</Directory>
<Directory Id="CommonAppDataFolder">
    <Directory Id="ProgramFileFolder" Name="Manufacturer">
        <!--Your " 'Bin' and 'AddIns' Folders"-->
        <Directory Id="AddinFolder" Name="AddIns">
            <Component Id="YourFile" Guid="{SOME GUID}">
                <!-- Just a file below your folder -->
                <File Id="YourFile"
                      Name="FileName"
                      Source="Source of the file"/>
            </Component>
        </Directory>
    </Directory>
</Directory>

上述代码可以在没有条件的情况下使用。

如果您真的想根据条件将它们安装到不同的文件夹,则需要复制您的组件。 以下是其中一个组件下的示例Condition

<Component Id="YourFile" Guid="{SOME GUID}">
    <Condition>YourCondition</Condition>
    <!-- Just a file below your folder -->
    <File Id="YourFile"
          Name="FileName"
          Source="Source of the file"/>
</Component>