我想在我的 WiX 工具集项目中使用 用户定义变量。 如果我尝试使用它们,构建过程将失败,并且我收到错误消息 WIX0150 未定义的预处理器变量 '$(MyVariable)'。
我遵循了 WiX Toolset 本身的文档:https://wixtoolset.org/docs/tools/preprocessor/
我的项目如下所示:
wixproj 文件
<Project Sdk="WixToolset.Sdk/4.0.3">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<DefineConstants>
<?define MyVariable = "Filepath" ?>
</DefineConstants>
</PropertyGroup>
</Project>
组件文件
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Fragment>
<Component Id="HandlerCmp" Directory="INSTALLFOLDER">
<File Source="$(MyVariable)" />
</Component>
</Fragment>
</Wix>
所以我在解决方案中遇到了项目属性。 在 Project -> Properties -> Build 下,您可以定义预处理器变量。 这将在 wixproj 文件中创建一个 DefineConstants 条目,如下所示:
<Project Sdk="WixToolset.Sdk/4.0.3">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<DefineConstants>MyVariable=Filepath;MyVariable2=Filepath2</DefineConstants>
</PropertyGroup>
</Project>
使用状态与问题中描述的相同:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Fragment>
<Component Id="HandlerCmp" Directory="INSTALLFOLDER">
<File Source="$(MyVariable)" />
</Component>
</Fragment>
</Wix>