powershell - 在 Powershell 中调用批处理脚本时如何传递等号?

标签 powershell batch-file

我们有一个批处理文件,用于调用基于 MSBuild 的构建过程。语法:

build App Target [ Additional MSBuild Arguments ]

在内部,它执行以下操作:

msbuild.exe %1.msbuild /t:%2 %3 %4 %5 %6 %7 %8 %9

这会导致对 MSBuild 的调用如下所示:

msbuild.exe App.msbuild /t:Target

When any argument contains the equal sign, =, Powershell completely removes it. My batch script never sees it. This does not happen with the standard cmd.exe command prompt.

For example, if I call

build App Target "/p:Property=Value"

这是传递给 MSBuild 的内容:

msbuild.exe App.msmbuild /t:Target /p:Property Value

我预料到了这个:

msbuild.exe App.msbuild /t:Target "/p:Property=Value"

我尝试过 Powershell 转义字符、标准命令提示符转义字符,甚至是我编造的东西:

build App Target "/p:Property=Value"
build App Target '/p:Property=Value'
build App Target /p:Property^=Value
build App Target /p:Property`=Value
build App Target /p:Property==Value

这一切都不起作用。 我该怎么做才能让等号不被剥离或删除?

最佳答案

我以前见过这种情况,并且找到了一种方法来欺骗它。我希望我能解释一下发生了什么,特别是“=”,但我不能。在您的情况下,如果您想将属性传递给 msbuild,我相当确定以下方法会起作用:

build App Target '"/p:Property=Value"' 

当回显时,会产生以下结果:

msbuild.exe App.msbuild /t:Target "/p:Property=Value"

关于powershell - 在 Powershell 中调用批处理脚本时如何传递等号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4940375/

相关文章:

powershell - 使用Powershell递归设置文件夹的权限?

powershell - 在 PowerShell 中输出日期/时间

powershell - 如何在Powershell中删除表单 "items"

python - 如何根据参数值 "skip"多功能 python 脚本中的各个函数

xml - 使用批处理文件编辑 XML

java - Ant 构建脚本以运行批处理文件,同时将用户输入传递给批处理文件

powershell - 如何将命令行的输出作为流逐行处理

powershell - Sitecore PowerShell 在脚本中快速搜索

batch-file - 如何使用 PuTTY/Plink 在 Windows 批处理文件中的设备上顺序执行多个命令?

batch-file - PuTTY/PSFTP 文件传输自动化的批处理文件