我有一个 WiX 安装程序,它将一堆扩展文件安装到另一个应用程序的应用程序目录中。为了确保文件最终位于正确的位置,我使用了一堆嵌套的 DirectorySearch 来查找应用程序目录。
该应用程序通常安装在遵循此模式的路径中:
\Program Files (x86)\CompanyName\ProductName\[version]\[environment]\[optional intermediate folder]\AppFolderName
也就是说,常见的安装文件夹包括:
\Program Files (x86)\CompanyName\ProductName\1.0\Prod\AppFolderName
\Program Files (x86)\CompanyName\ProductName\1.1\Prod\OptionalFolderName\AppFolderName
\Program Files (x86)\CompanyName\ProductName\1.2\Test\AppFolderName
\Program Files (x86)\CompanyName\ProductName\1.2\Test\OptionalFolderName\AppFolderName
为了处理这个问题,我使用了一组嵌套的 DirectorySearch 元素来将路径分配给属性。如果存在可选文件夹 (OptionalFolderName),则以下操作有效:
<Property Id="SOMEAPPFOLDER">
<DirectorySearch Id="ProgramFilesFolder" Path="[ProgramFilesFolder]">
<DirectorySearch Id="CompanyNameFolder" Path="CompanyName">
<DirectorySearch Id="ProductFolder" Path="ProductName">
<DirectorySearch Id="EnvironmentFolder" Path="$(var.ENVIRONMENTNAME)" Depth="2">
<DirectorySearch Id="OptionalIntermediateFolder" Path="OptionalFolderName">
<DirectorySearch Id="AppFolder" Path="AppFolderName" AssignToProperty="yes">
<FileSearch Id="AppNameExe" Name="AppName.exe" MinVersion="$(var.MIN_VERSION).0" MaxVersion="$(var.MAX_VERSION).999" />
</DirectorySearch>
</DirectorySearch>
</DirectorySearch>
</DirectorySearch>
</DirectorySearch>
</DirectorySearch>
</Property>
但是,由于 OptionalFolderName 是可选的,我想使用 DirectorySearch 来确定应用程序文件夹是直接在环境文件夹下还是下一级。为了做到这一点,我将搜索树更改为:
<Property Id="SOMEAPPFOLDER">
<DirectorySearch Id="ProgramFilesFolder" Path="[ProgramFilesFolder]">
<DirectorySearch Id="CompanyNameFolder" Path="CompanyName">
<DirectorySearch Id="ProductFolder" Path="ProductName">
<DirectorySearch Id="EnvironmentFolder" Path="$(var.ENVIRONMENTNAME)" Depth="2">
<DirectorySearch Id="AppFolder" Path="AppFolderName" Depth="2" AssignToProperty="yes">
<FileSearch Id="AppNameExe" Name="AppName.exe" MinVersion="$(var.MIN_VERSION).0" MaxVersion="$(var.MAX_VERSION).999" />
</DirectorySearch>
</DirectorySearch>
</DirectorySearch>
</DirectorySearch>
</DirectorySearch>
</Property>
但是,如果存在可选文件夹,则更高版本不起作用,但如果不存在,则可以使用。换句话说,就好像Depth 属性之一被忽略了;我的猜测是这是因为我在树中的不同级别使用了两次深度属性。
关于如何解决这个问题的任何建议?
更新- 添加了来自 msiexec /i [msiname] /l*v [logfile] 的日志片段提取:
Action 14:38:47: AppSearch. Searching for installed applications
Action start 14:38:47: AppSearch.
AppSearch: Property: SOMEAPPFOLDER, Signature: AppFolder
MSI (c) (00:90) [14:38:47:065]: Note: 1: 1322 2:
MSI (c) (00:90) [14:38:47:065]: Note: 1: 1322 2:
MSI (c) (00:90) [14:38:47:065]: Note: 1: 1324 2: [environmentname] 3: 1
MSI (c) (00:90) [14:38:47:065]: Note: 1: 1325 2: CompanyName
Action ended 14:38:47: AppSearch. Return value 1.
MSI (c) (00:90) [14:38:47:066]: Doing action: LaunchConditions
MSI (c) (00:90) [14:38:47:067]: Note: 1: 2205 2: 3: ActionText
Action 14:38:47: LaunchConditions. Evaluating launch conditions
Action start 14:38:47: LaunchConditions.
MSI (c) (00:A8) [14:38:47:069]: Font created. Charset: Req=0, Ret=0, Font: Req=MS Shell Dlg, Ret=MS Shell Dlg
Couldn't find the AppFolderName app folder for [environment/version].
MSI (c) (00:90) [14:38:48:543]: Note: 1: 2205 2: 3: Error
MSI (c) (00:90) [14:38:48:543]: Note: 1: 2228 2: 3: Error 4: SELECT `Message` FROM `Error` WHERE `Error` = 1709
MSI (c) (00:90) [14:38:48:543]: Product: [productname] -- Couldn't find the AppFolderName app folder for [environment/version].
Action ended 14:38:48: LaunchConditions. Return value 3.