【发布时间】:2018-02-14 16:33:20
【问题描述】:
这不是关于 Visual Studio 的帖子,因为我可以在 powershell 命令行上复制该问题
我正在尝试在 Visual Studio 2015 中启动一个 powershell 脚本作为构建后事件的一部分。为了完整起见,我的构建后事件代码是:
powershell -executionPolicy bypass -Command “& {Invoke-command -scriptblock {Param($path); write-host $path} -ArgumentList '$(ProjectDir)'}"
然后这会被 VS 转换成一个批处理文件,如下所示:
powershell -executionPolicy bypass -Command “& {Invoke-command -scriptblock {Param($path); write-host $path} -ArgumentList 'd:\somepath\somefile.msi'}"
它的目的是为了反驳这样一个事实,即开发人员在不同的驱动器上拥有数据,所以我不知道脚本最终会放在哪里。我将在路径字符串的开头使用卷信息,但现在,让它回显路径将是一个胜利..
如果我使用 Invoke-Command 并运行它,一切都会按预期工作:
PS D:\> Invoke-command -scriptblock {Param($path); write-host $path} -ArgumentList 'd:\somepath\somefile.msi'
d:\somepath\somefile.msi
如果我将它包装到要传递给 powershell 的 –command 参数中,argumentlist 永远不会填充参数,并且我会在脚本块中得到一个空的 $path 字符串。
PS D:\ > powershell -Command “& {Invoke-command -scriptblock {Param($path); write-host $path} -ArgumentList 'd:\somepath\somefile.msi'}"
关于我哪里出错了有什么建议吗?
非常感谢
【问题讨论】:
标签: powershell-3.0