我们有一个批处理文件,用于调用基于 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/