gpt4 book ai didi

如果在同一棵树中多次使用 WiX DirectorySearch/@Depth 将被忽略

转载 作者:行者123 更新时间:2023-12-04 17:35:57 26 4
gpt4 key购买 nike

我有一个 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.

最佳答案

Depth的行为当FileSearch使用
DepthFileSearch 时工作方式不同是 DirectorySearch 的直系后代.

在正常情况下,Depth指定高于指定路径的最大文件夹级别数。但是,如果 FileSearch是直系后代,Depth指定在指定路径下查找文件的最大文件夹级别数。

换句话说,无法为作为文件的直接父级的目录指定深度。

示例

让我们看看你粘贴的代码:

<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允许 ProductFolder 和 EnvironmentFolder 之间的两个目录级别,但第二次使用 Depth指的是 AppFolder之间的层数和 AppNameExe .

解决方法

以下 xml 使用两个搜索来解决该问题:
<!-- Locate the parent directory first -->
<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="1">
<DirectorySearch Id="AppFolder" Path="AppFolderName" Depth="1" />
</DirectorySearch>
</DirectorySearch>
</DirectorySearch>
</DirectorySearch>
</Property>

<!-- Now, look for the file in the above directory -->
<Property Id="APPFILEEXISTS">
<DirectorySearch Id="AppFolder" Path="SOMEAPPFOLDER">
<FileSearch Id="AppNameExe" Name="AppName.exe" MinVersion="$(var.MIN_VERSION).0"
MaxVersion="$(var.MAX_VERSION).999" />
</DirectorySearch>
</Property>

关于如果在同一棵树中多次使用 WiX DirectorySearch/@Depth 将被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18909240/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com