我在使用 wix 创建 Windows 安装程序时遇到以下错误。
未定义的预处理器变量“$(var.WixInstall.TargetPath)”。 WixInstaller D:\work\Extractor\WixInstaller\Product.wxs
请注意:我已经尝试过以下答案但没有收获
[Wix“未定义的预处理器变量” https://stackoverflow.com/questions/32784833/wix-undefined-preprocessor-variable%5D ,
[WiX 未定义的预处理器变量 https://stackoverflow.com/questions/2063630/wix-undefined-preprocessor-variable%5D ,
[WiX - 未定义的预处理器变量“$(var.SetupProject1.TargetDir)” https://stackoverflow.com/questions/47995549/wix-undefined-preprocessor-variable-var-setupproject1-targetdir%5D
产品.wxs代码
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="WixInstaller" Language="1033" Version="1.0.0.0" Manufacturer="" UpgradeCode="PUT-GUID-HERE">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate />
<Feature Id="ProductFeature" Title="WixInstaller" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="WixInstaller" />
</Directory>
</Directory>
</Fragment>
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Id="ProductComponent">
<File Source="$(var.WixInstall.TargetPath)" />
</Component>
</ComponentGroup>
</Fragment>
</Wix>
获得心跳:首先要做的事情:编译源代码,以便检查是否存在其他问题:
-
绝对路径:请尝试对您知道目标位置存在的文件的完整路径进行硬编码:
<File Source="D:\My Files\MyBinary.exe" />
-
制造商:接下来设置"Manufacturer" attribute
对某事。只要有东西存在,任何事情都会发生。显然,请输入您的公司名称。
=> 尝试编译。这应该会成功。
缺少定义: 好吧,有了心跳,让我们尝试解决这个问题。您从哪里获得此预处理器构造:
<File Source="$(var.WixInstall.TargetPath)" />
这是来自某个样本还是其他什么?我假设"WixInstall"
是指 Visual Studio 解决方案中的 WiX 项目本身吗?通常,您可以像这样通过名称引用解决方案中的项目,但通常您引用另一个项目,例如“MyBinaryProject”,并且引用其构建输出,如下所示:
<File Source="$(var.MyBinaryProject.TargetPath)" />
您需要确保您引用的项目实际上位于 Visual Studio 解决方案中。并且您需要添加对它的引用:
- 右键点击
"References"
在你的 WiX 项目中 =>Add Reference...
- Under
"Projects"
选择您要参考的项目,按Add
and OK
.
WiX 文档: 使用项目引用和变量 http://wixtoolset.org/documentation/manual/v3/votive/votive_project_references.html- 请参阅 WiX 文档条目,了解引用其他 Visual Studio 项目时可用的内置变量的详细信息。
常规预处理器变量:除了添加对另一个 Visual Studio 项目的引用时获得的内置预处理器变量外,您还可以定义自己的变量:
<?define MyTest= "D:\My Files\MyBinary.exe" ?>
<...>
<File Source="$(var.MyTest)" />
Links:
- 有关高级预处理器功能和其他内容的更多信息:Wix 安装程序:在命令行执行 MSIEXEC 管理安装时设置组件条件属性 https://stackoverflow.com/questions/49449985/wix-installer-setting-component-condition-property-when-doing-a-msiexec-admin/49501700#49501700
- 关于 WiX 中的不同变量类型:WiX(Windows Installer Xml),创建通用变量 https://stackoverflow.com/questions/50444241/wix-windows-installer-xml-create-universal-variables/50452114#50452114
- WiX 快速入门简版 https://stackoverflow.com/questions/63305272/adventures-in-installing-a-c-wpf-application-wix/63308043#63308043
- WiX快速入门很长版本 https://stackoverflow.com/questions/25004226/msi-vs-nuget-packages-which-are-is-better-for-continuous-delivery/25005864#25005864
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)