文件包的说明XML
- 更新时间2025-10-21
- 阅读时长23分钟
Instructions XML文件为Package Manager提供程序包安装的定制化运行选项。
- <targetAttributes>
- <customDirectories>
- <shortcuts>
- <returnCodeConventions>
- <customExecutes>
- <osUninstallEntry>
将Instructions XML文件命名为instructions,忽略文件扩展名,将其放在文件程序包的data根目录下。
以下是文件程序包的Instructions文件示例。
<instructions>
<targetAttributes readOnly="allReadOnly"/>
<customDirectories>
<customDirectory name="customDir1" path="D:\subdir"/>
<customDirectory name="customDir2" path="\\myserver\subdir"/>
</customDirectories>
<shortcuts>
<shortcut>
<destination root="ProgramMenu" path="Test\Shortcut.lnk">
<localizedDestination root="ProgramMenu" path="Test\Verknüpfung.lnk" language="de"/>
<localizedDestination root="ProgramMenu" path="Test\Raccourci.lnk" language="fr"/>
<localizedDestination root="ProgramMenu" path="Test\ショートカット.lnk" language="ja"/>
<localizedDestination root="ProgramMenu" path="Test\바로가기.lnk" language="ko"/>
<localizedDestination root="ProgramMenu" path="Test\快捷方式.lnk" language="zh-CN"/>
</destination>
<target root="Program Files" path="Shortcuts\executable.exe"/>
</shortcut>
</shortcuts>
<customExecutes>
<customExecute root="Documents" exeName="executable.exe"/>
</customExecutes>
</instructions>
<targetAttributes>元素
<targetAttributes>提供了Package Manager在目标位置安装文件的位置选项。
<targetAttributes>是一个空元素,表示其有属性,但是不包含元素或文本内容。该元素具有以下属性:
| 属性名称 | 类型 | 可能值 | 详细信息 | 范例 |
|---|---|---|---|---|
| readOnly | 枚举 | |
| <targetAttributes readOnly="allReadOnly"/> |
<customDirectories>元素
<customDirectories>元素提供Package Manager在目标系统上安装文件的绝对路径位置列表。
<customDirectories>包含<customDirectory>子元素。
<customDirectory>元素
<customDirectory>元素定义Package Manager在目标系统上安装文件的绝对路径或网络路径。
Instructions文件中可以包含<customDirectory>的多个实例。
| 属性名称 | 类型 | 值 | 范例 |
|---|---|---|---|
| name | 字符串 | 有效的Windows目录名称字符:
| <customDirectory name="examplename1" path="D:\bin"/> |
| path | 字符串 | 目标系统上的绝对路径或网络路径 | <customDirectory name="examplename2" path="\\servername\sharename\subdir"/> |
<shortcuts>元素
<shortcuts>元素定义了Package Manager在安装的同时创建快捷方式的列表。
<shortcuts>包含<shortcut>子元素。
<shortcut>元素
<shortcut>元素定义了Package Manager在安装的同时创建一个快捷方式。
- <destination>
- <target>
<destination>元素
<destination>元素指定Package Manager创建的快捷方式所在的位置。
<destination>是必需的属性,可以有一个或多个<localizedDestination>子属性。该元素具有以下属性:
| 属性名称 | 类型 | 值 | 范例 |
|---|---|---|---|
| root | 字符串 | 支持的目标根目录。具有windows_all架构的程序包无法使用64位特定目标根目录,例如ProgramFiles_64或LV2017DIR64。 | <destination root="Startup" path="testShortcut.lnk"/> |
| path | 字符串 | 安装根目录后面的路径和文件名称。关于语法要求,请参考 引号的XML语法规则。 | <destination root="ProgramFiles" path="Shortcuts\test.exe"/> |
<localizedDestination>元素
<localizedDestination>元素指定使用指定语言安装文件程序包时,快捷方式文件使用的其他本地化路径。
<localizedDestination>是一个空元素,表示其有属性,但是不包含元素或文本内容。该元素具有以下属性:
| 属性名称 | 类型 | 值 | 范例 |
|---|---|---|---|
| root | 字符串 | 支持的目标根目录。具有windows_all架构的程序包无法使用64位特定目标根目录,例如ProgramFiles_64或LV2017DIR64。 | <localizedDestination root="ProgramMenu"/> |
| path | 字符串 | 根目录后面的路径和文件名称。 | <localizedDestination root="ProgramMenu" path="Test\Verknüpfung.lnk" /> |
| language | 字符串 |
路径所使用语言的代码可能值:
|
<localizedDestination root="ProgramMenu" path="Test\Verknüpfung.lnk" language="de"/> |
<target>元素
<target>元素指定Package Manager创建的快捷方式指向文件的位置。
<target>是一个空元素,表示其有属性,但是不包含元素或文本内容。该元素具有以下属性:
| 属性名称 | 类型 | 值 | 范例 |
|---|---|---|---|
| root | 字符串 | 支持的目标根目录。具有windows_all架构的程序包无法使用64位特定目标根目录,例如ProgramFiles_64或LV2017DIR64。 | <target root="Startup" path="testShortcut.lnk"/> |
| path | 字符串 | 安装根目录后面的路径和文件名称。关于语法要求,请参考 引号的XML语法规则。 | <target root="ProgramFiles" path="Shortcuts\test.exe"/> |
| arguments | 字符串 | 传递给目标文件的可选参数。关于语法要求,请参考 引号的XML语法规则。 | <target root="ProgramFiles" path="Shortcuts\test.exe" arguments="--argument1"/> |
<returnCodeConventions>元素
<returnCodeConventions>元素提供Package Manager执行该程序包自定义操作时使用的自定义返回代码规范列表。
<returnCodeConventions>在Instructions文件中是可选的,但可以包含一个或多个<returnCodeConvention>子元素。
<returnCodeConvention>元素
<returnCodeConvention>元素定义如何解译此程序包中一个或多个自定义执行的返回代码。
<returnCodeConvention>可包含一个或多个可选的<returnCode>子元素。<returnCode>规则按照其定义的顺序进行评估。
| 属性名称 | 类型 | 值 | 范例 |
|---|---|---|---|
| name | 字符串 | 该返回代码规范的唯一名称。该程序包中的自定义执行可在returnCodeConvention字段中使用该名称关联至该返回代码规范。 | <returnCodeConvention name="alwaysReboot" defaultResult="rebootRequired"/> |
| defaultResult | 枚举 | 表示与现有返回代码映射规则不匹配的返回代码的语义结果。
|
<returnCodeConvention name="ignore" defaultResult="success"/> |
<returnCode>元素
<returnCode>元素定义其父<returnCodeConvention>的返回代码映射规则。
<returnCode>是一个空元素,表示元素有属性,但是不包含元素或文本内容。该元素具有以下属性:
| 属性名称 | 类型 | 值 | 范例 |
|---|---|---|---|
| min | 整型 | 表示该规则匹配的返回代码范围的下限。不能与value属性组合。 | <returnCode min="0" max="1024" result="success"/> |
| max | 整型 | 表示该规则匹配的返回代码范围的上限。不能与value属性组合。 | <returnCode min="-50" max="-1" result="success"/> |
| value | 整型 | 表示该规则匹配的单一返回代码。不能与min或max属性组合。 | <returnCode value="1641" result="rebootRequired"/> |
| result | 枚举 | 表示匹配该规则的返回代码的语义结果。 | <returnCode value="3010" result="rebootRequired"/> |
<customExecutes>元素
<customExecutes>元素提供了Package Manager在软件包上执行的自定义操作。
<customExecutes>包含<customExecute>子元素。
<customExecute>元素
<customExecute>元素定义Package Manager对程序包执行的一个自定义操作。
<customExecute>是Instructions文件中的可选元素,可在程序包中包含任意所需数量的该元素。<customExecute>是空元素,表示该元素有属性,但是不包含元素或文本内容。该元素具有以下属性:
| 属性名称 | 类型 | 必需 | 值 | 说明 | 范例 |
|---|---|---|---|---|---|
| root | 字符串 | 是 | 可执行文件的根路径。具有windows_all架构的程序包无法使用64位特定目标根目录,例如ProgramFiles_64或LV2017DIR64。 | 指定可执行文件的根路径。 支持的目标根目录。请参考安装目标根目录了解支持的目标根目录。 备注 如要运行可执行文件,必须先安装包含可执行文件的程序包。通过将目标根路径设置为NIPkgMgrTempUnique并将schedule属性设置为post,可配置程序包临时安装可执行文件。然后,Package Manager将程序包安装到NIPkgMgrTempUnique目录,并运行可执行文件,最后删除目录中的文件。 |
<customExecute root="Documents" exeName="executable.exe"/> |
| exeName | 字符串 | 是 | 可执行文件的文件名。 | 指定可执行文件的文件名。 可以包含一个相对于根目录的路径。关于语法要求,请参考 引号的XML语法规则。 |
<customExecute root="ProgramData" exeName="actions\executable.exe"/> |
| arguments | 字符串 | 否 | 传递给可执行文件的命令行参数。 | 指定Package Manager传递给可执行文件的命令行参数。 值格式化。可包括一个支持的目标根目录,和/或下列参数: 备注 参数区分大小写。关于语法要求,请参考 引号的XML语法规则。 |
|
| step | 枚举 | 否 |
|
指定执行何种操作时Package Manager运行可执行文件。
备注 在开发程序包时,如果将step的值设置为uninstall,将ignoreErrors的值设置为y,可避免Package Manager无法从目标系统中移除程序包的情况发生。 |
<customExecute step="uninstall" root="ProgramData" ignoreErros="y" exeName="actions\executable.exe"/> |
| schedule | 枚举 | 否 |
|
指定Package Manager在某个操作步骤上运行可执行文件。 如忽略该属性,Package Manager使用默认值。 |
<customExecute step="install" schedule="post" root="ProgramData" exeName="executable.exe"/> |
| wait | 布尔 | 否 |
|
指定自定义操作是否同步或异步。同步时,Package Manager应该等待自定义操作结束后才继续。异步时,Package Manager不做任何等待。 如忽略该属性,Package Manager使用默认值。 |
<customExecute root="ProgramData" exeName="executable.exe" wait="n"/> |
| ignoreErrors | 布尔 | 否 |
|
如无法运行可执行文件或可执行文件返回非0值,Package Manager是否报告错误。
|
<customExecute root="ProgramData" exeName="executable.exe" wait="y" ignoreErrors="y"/> |
| hideConsoleWindow | 布尔 | 否 |
|
指定是否为控制台应用程序银行控制台窗口。
|
<customExecute root="ProgramData" exeName="executable.exe" hideConsoleWindow="y"/> |
| ignoreLaunchErrors | 布尔 | 否 |
|
指定Package Manager无法运行或无法找到可执行文件时是否报错。该属性不能与ignoreErrors组合使用。 | <customExecute root="ProgramData" exeName="executable.exe" ignoreLaunchErrors="y"/> |
| returnCodeConvention | 字符串 | 否 | 必须匹配预定义规范的名称或该程序包中定义的<returnCodeConvention>元素。下列预定义的规范可用:
|
表示如何解译可执行文件返回的返回代码。
|
<customExecute root="ProgramData" exeName="executable.exe" returnCodeConvention="installer"/> |
Postall可执行程序
如Instructions文件中包含<customExecute>元素,元素的属性为schedule="postall",会影响Package Manager生成的程序包的安装过程。
postall值表示Package Manager在完成安装、再次安装、卸载步骤后运行可执行文件。
- Package Manager按照程序包安装的指定顺序运行postall可执行文件。首先安装依赖项。
- 如果程序包中只有一个postall可执行文件失败,Package Manager认为程序包成功安装。
- 当有包含postall可执行文件的多个程序包,如果一个postall可执行文件运行失败,Package Manager不运行其余的可执行文件。如果没有其他错误发生,则认为程序包已成功安装。
- 如安装程序包失败,无论是MSI出错还是pre或post, 可执行文件出错,Package Manager将显示错误消息,表示程序包安装失败。然后,Package Manager运行程序包中的所有可执行文件。NI Package Manager不认为破损的程序包已被安装,也不在破损的程序包上运行postall可执行文件。错误发生前完成安装的程序包为已安装状态。NI Package Manager将为这些程序包运行postall可执行文件。
引号的XML语法规则
查看引号的XML语法规则以确保符合Microsoft的条件语句语法,并将路径用引号括起来。
必须将literal文本包含在引号内,以符合Microsoft条件语句的语法。Instructions XML语法提供了两种途径:
- 使用单引号分隔XML字符串。允许在字符串内使用双引号。例如:
<customExecute condition='IEDETECTED~="Yes" AND VersionNT64 = 601 AND NIRUNNINGINSILENTMODE'/>
- 使用双引号的XML转义符"分隔XML字符串中的literal文本。通过XML转义字符,您可以使用双引号或单引号来分隔XML字符串。例如:
<customExecute condition="IEDETECTED~="Yes" AND VersionNT64 = 601 AND NIRUNNINGINSILENTMODE"/>
如路径中包含空格,将路径用引号括起来。路径中不允许使用单引号:
- 使用双引号的XML转义符",将路径括起来。例如:
<customExecute exeName=""VC RunTime Installer.exe"" arguments="/q /norestart" inPackage="y"/>
自定义执行范例
以下代码调用程序包可能已安装的PowerShell脚本,并在安装后传递两个参数。
<customExecute root="BootVolume" exeName="Windows\System32\WindowsPowerShell\v1.0\powershell.exe" arguments="-File "%ProgramData%\My App Name\MyInstallScript.ps1" "argument 1" "argument 2"" step="install" schedule="post" wait="y" ignoreErrors="n" hideConsoleWindow="y" />
<osUninstallEntry>元素
<osUninstallEntry>元素提供了程序包在添加/删除程序界面中显示的可选说明。
<osUninstallEntry>为空元素。也就是说,它有属性,但不包含元素或文本内容。<osUninstallEntry>具有以下属性:
| 属性名称 | 类型 | 可能值 | 详细信息 | 范例 |
|---|---|---|---|---|
| ux | 枚举 |
|
对于第三方程序包,oem值允许程序包在已安装的应用程序列表中显示为一级项。执行修改和卸载操作时,添加/删除程序界面只指向已命名的程序包。 | <osUninstallEntry ux="oem"/> |
相关内容
- 文件程序包的安装目标根目录
在数据文件夹下创建的目录用于告知在构建程序包时Package Manager安装文件的位置。