0

我需要在 wix 工具集上收集一个目录,但是这个目录将用于命名构建版本号。我知道如何定义一个静态常量,但是可以创建一个变量吗?

我在论坛上搜索,但从未找到基于外部变量的收获。

<PropertyGroup>
  <DefineConstants>BasePath=..\Files\$(build);</DefineConstants>
</PropertyGroup>

<HeatDirectory 
OutputFile="HarvestedCopyFiles.wxs" 
DirectoryRefId="INSTALLFOLDER" 
ComponentGroupName="HarvestedCopyFilesComponent" 
SuppressCom="true" 
Directory="..\Files" 
SuppressFragments="true" 
SuppressRegistry="true" 
SuppressRootDirectory="true" 
AutoGenerateGuids="false" 
GenerateGuidsNow="true" 
ToolPath="$(WixToolPath)" 
PreprocessorVariable="var.BasePath" />

我该怎么做才能使这种$(build)变量起作用?有没有办法将它链接到我variable.wxi得到的文件:<?define ProjectBuild = "421" ?>

4

1 回答 1

0

您可以通过将 BeforeBuild 目标添加到您的 wixproj 文件来执行类似的操作:

<Target Name="BeforeBuild">
    <ItemGroup>
        <FileThatExists Include="..\Files\**\FileThatExists.txt"/>
    </ItemGroup>

    <PropertyGroup>
        <Build>@(FileThatExists->'%(RecursiveDir)')</Build>
        <BasePath>..\Files\$(Build)\</BasePath>
        <DefineConstants>
            $(DefineConstants);
            Build=$(Build);
            BasePath=$(BasePath);
        </DefineConstants>    
    </PropertyGroup>

    <HeatDirectory 
        OutputFile="HarvestedCopyFiles.wxs" 
        DirectoryRefId="INSTALLFOLDER" 
        ComponentGroupName="HarvestedCopyFilesComponent" 
        SuppressCom="true" 
        Directory="$(BasePath)" 
        SuppressFragments="true" 
        SuppressRegistry="true" 
        SuppressRootDirectory="true" 
        AutoGenerateGuids="false" 
        GenerateGuidsNow="true" 
        ToolPath="$(WixToolPath)" 
        PreprocessorVariable="var.BasePath" 
    />
</Target>

它的作用是通过巧妙地使用 ItemGroup 元数据属性来计算构建文件夹的 #。您也可以创建另一个目标来获取该文件夹名称,并且您应该能够在 SO 上找到一些示例。

我们将 Build 属性值设置为我们制作的项目的 RecursiveDir 元数据,然后还定义 BasePath 值。

接下来,我们将更新DefineConstants 属性中包含的值。这是允许您将变量键值对传递给 Candle wix 编译器的属性,它允许您在安装程序源代码中使用 $(var.Build) 和 $(var.BasePath) 之类的语法。

最后,我们调用 HeatDirectory 任务,它将收集您的 build# 文件夹并生成 HarvestedCopyFiles.wxs 文件。

我想建议定义 HarvestDirectory 目标使用的项目“HarvestDirectory”,如果存在一个或多个 HarvestDirectory 项目,该目标将运行。

为此,您只需<HeatDirectory>

    <PropertyGroup>
        <HarvestDirectoryAutogenerateGuids>true</HarvestDirectoryAutogenerateGuids>
        <HarvestDirectoryGenerateGuidsNow>true</HarvestDirectoryGenerateGuidsNow>
    </PropertyGroup>
    <ItemGroup>
        <HarvestDirectory Include="$(BasePath)">
            DirectoryRefId="INSTALLFOLDER" 
            ComponentGroupName="HarvestedCopyFilesComponent"  
            PreprocessorVariable="var.BasePath"
            SuppressCom="true"
            SuppressRegistry="true"
            SuppressRootDirectory="true"
        </HarvestDirectory>
    </ItemGroup>

我更喜欢这种方法,因为它会自动将生成的文件包含在您的编译源中,因此您不必在项目中包含不存在的文件。

于 2019-08-23T20:16:05.287 回答