wix - 在 wix 安装程序脚本中有条件地设置快捷方式参数
问题描述
我有以下 WIX 快捷方式。
<!--Desktop shortcuts-->
<Directory Id="DesktopFolder" Name="Desktop">
<Component Id="CMP_DesktopShortcuts" Guid="{guidblah}">
<Shortcut Id="Shotcut_Editor_Desktop"
Name ="Software"
Description="Software Description"
Arguments="$(var.CmdLineArgs)"
Target="blah.exe">
</Shortcut>
<RegistryValue Root="HKCU"
Key="Software\blah"
Name="DesktopShortcutInstalled"
Type="integer"
Value="1"
KeyPath="yes"
/>
</Component>
</Directory>
我根据我正在构建的安装程序在我的构建脚本中设置 CmdLineArgs。我的一个构建脚本没有命令行参数,因此将 CmdLineArgs 设置为 null。
然后我得到这个错误:
错误 CNDL0006:Shortcut/@Arguments 属性的值不能为空字符串。如果不需要值,只需删除整个属性。
仅当 $(var.CmdLineArgs) 不为空时,如何有条件地设置参数?
解决方案
使用预处理器根据变量有条件地编译Shortcut
带有或不带有属性的元素。Arguments
<?ifdef CmdLineArgs?>
<Shortcut Id="Shotcut_Editor_Desktop"
Name ="Software"
Description="Software Description"
Arguments="$(var.CmdLineArgs)"
Target="blah.exe">
</Shortcut>
<?else?>
<Shortcut Id="Shotcut_Editor_Desktop"
Name ="Software"
Description="Software Description"
Target="blah.exe">
</Shortcut>
<?endif?>
不幸的是,这里有一些重复,因为预处理器条件不能应用于属性级别,元素是最小的粒度。
以下是无效的XML:
<Shortcut Id="Shotcut_Editor_Desktop"
Name ="Software"
Description="Software Description"
<?ifdef CmdLineArgs?>
Arguments="$(var.CmdLineArgs)"
<?endif?>
Target="blah.exe">
</Shortcut>
您也可以通过对其他属性使用预处理器变量来消除一些重复,例如:
<?ifdef CmdLineArgs?>
<Shortcut Id="Shotcut_Editor_Desktop"
Name ="$(var.ProductName)"
Description="$(var.ProductDescription)"
Arguments="$(var.CmdLineArgs)"
Target="$(var.ProductExeFile)">
</Shortcut>
<?else?>
<Shortcut Id="Shotcut_Editor_Desktop"
Name ="$(var.ProductName)"
Description="$(var.ProductDescription)"
Target="$(var.ProductExeFile)">
</Shortcut>
<?endif?>
该Id
属性不太可能改变,所以我保留它是为了更好的可读性。
推荐阅读
- javascript - Google map api:按类别的多个侧边栏不起作用(文本不出现)
- java - 如何从 Firebase 实时数据库参考中重复获取价值?
- java - 在 JAVA 中的菜单项内的菜单内添加菜单项
- python - 如何手动重构 python 项目?
- ios - 如何从另一个视图(swift 4)对选项卡栏控制器中的特定视图执行 performSegue
- excel - 比较两列并突出显示任何差异
- javascript - 迭代嵌套的javascript对象并在jsx中渲染的最高效方法是什么
- c - execl后的printf没有显示
- vba - 查明附件是嵌入的还是附加的
- javascript - 模式未通过链接单击打开