如何调用在PowerShell中的批处理脚本时,我传递一个等号? [英] How do I pass an equal sign when calling a batch script in Powershell?

查看:205
本文介绍了如何调用在PowerShell中的批处理脚本时,我传递一个等号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们必须调用我们基于MSBuild的建造过程中的批处理文件。语法:

We have a batch file that invokes our MSBuild-based build process. Syntax:

build App Target [ Additional MSBuild Arguments ]

在内部,它这样做:

Internally, it does this:

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

这导致像这样来的MSBuild电话:

Which results in calls to MSBuild that look like this:


msbuild.exe App.msbuild /t:Target

当任何参数包含等号, = ,Powershell的完全去除。我的批处理脚本永远看不到它。这不符合标准发生的cmd.exe 命令提示符。

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.

例如,如果我叫

build App Target "/p:Property=Value"

这是什么获取传递给MSBuild的:

this is what gets passed to MSBuild:

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

我预计:

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

我试过PowerShell的转义字符,标准的命令提示符的转义字符,连东西我提出了:

I've tried the Powershell escape character, the standard Command Prompt escape character, and even stuff I made up:

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下面的工作:

I've seen this before and have found a way to trick it out. I wish I could explain what's going on in particular with the '=' but I cannot. In your situation I'm fairly certain the following will work if you want to pass properties to msbuild:

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

在回荡,这将产生以下内容:

When echoed, this produces the following:

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

这篇关于如何调用在PowerShell中的批处理脚本时,我传递一个等号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆