首页 > 解决方案 > 将多个参数传递给高级安装程序中的 Powershell 内联脚本

问题描述

我正在使用高级安装程序来创建 msi 包我想在安装完成后将一些文件和文件夹复制到“[APPDIR]”(我知道我可以通过在高级安装程序中将文件和文件夹添加到文件和文件夹部分来做到这一点,但我没有我不想这样做,因为我的文件和文件夹在客户机器的每次安装中都是动态的)我编写了一个如下所示的内联 PowerShell 脚本

> Param( [string] $source, [string] $dest )
$exclude = @('web.config')
> Get-ChildItem $source -Recurse -Exclude $exclude | Copy-Item
> -Destination {Join-Path $dest $_.FullName.Substring($source.length)}

在参数部分,我这样填写"[SourceDir]Project", "[APPDIR]Project"

但它不起作用。为什么?

标签: powershellinstallationcustom-actionadvanced-installer

解决方案


此后,阿巴斯确认问题出在命令行(参数)语法之一:

参数部分 - 从Advanced Installer传递给 PowerShell 脚本的内容- 填写为:

"[SourceDir]Project", "[APPDIR]Project"  # !! WRONG, due to the comma

而它应该是:

"[SourceDir]Project" "[APPDIR]Project"  # OK: *space-separated* arguments

在 PowerShell 中调用脚本/函数/cmdlet 的工作方式与在shell中一样,而不是在编程语言中;也就是说,您必须用空格分隔正在传递的参数。

相比之下,,在标记之间使用构造了一个作为单个参数传递的数组。

从 PowerShell 运行Get-Help about_Command_Syntax以获取更多信息。


推荐阅读