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
Which results in calls to MSBuild that look like this:
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"
this is what gets passed to MSBuild:
msbuild.exe App.msmbuild /t:Target /p:Property Value
I expected this:
msbuild.exe App.msbuild /t:Target "/p:Property=Value"
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
None of it works. What do I do to get the equal sign to not be stripped out or removed?
[ == ] (Double Equals) The "IF" command uses this to test if two strings are equal: IF "%1" == "" GOTO HELP. means that if the first parameter on the command line after the batch file name is equal to nothing, that is, if a first parameter is not given, the batch file is to go to the HELP label.
When used in a command line, script, or batch file, %1 is used to represent a variable or matched string. For example, in a Microsoft batch file, %1 can print what is entered after the batch file name.
In the batch script, you can get the value of any argument using a % followed by its numerical position on the command line. The first item passed is always %1 the second item is always %2 and so on. If you require all arguments, then you can simply use %* in a batch script.
Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With