Behavior of Depth
when FileSearch
is used
Depth
works differently when FileSearch
is an immediate descendant of DirectorySearch
.
In the normal case, Depth
specifies the maximum number of folder levels above the specified path. However, if FileSearch
is an immediate descendant, Depth
specifies the maximum number of folder levels to look for the file below the specified path.
In other words, there's no way to specify the depth for a directory that is an immediate parent of a file.
Example
Let's look at the code you've pasted:
<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>
In the above, the first use of Depth
allows two directory levels between ProductFolder and EnvironmentFolder, but the second use of Depth
refers to the number of levels between AppFolder
and AppNameExe
.
Workaround
The following xml uses two searches to workaround the problem:
<!-- 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>