2

I'm using cmd from Shake and having trouble forming the following command line ...

msbuild a.sln /p:Configuration=Debug /p:Platform="Any CPU"

When I try escaping the double quote, the escaping and string quoting flows too far and get this error ...

Development.Shake.cmd, system command failed
Command: msbuild a.sln /p:Configuration=Debug "/p:Platform=\"Any CPU\""
Exit code: 1

I've tried 3 ways ...

cmd "msbuild a.sln /p:Configuration=Debug /p:Platform=\"Any CPU\""
cmd "msbuild a.sln /p:Configuration=Debug" ["/p:Platform=\"Any CPU\""]
cmd "msbuild" ["a.sln", "/p:Configuration=Debug", "/p:Platform=\"Any CPU\""]

I am running this on Windows.

philderbeast
  • 267
  • 2
  • 8
  • 2
    I think you should be able to pass `"/p:Platform=Any CPU"` instead, and `msbuild` should work equivalently. I suspect to pass exactly that string to `msbuild` you need to `Shell` to the first option, but I'll check properly later. – Neil Mitchell Jul 26 '14 at 07:16

1 Answers1

2

I wrote a little C program (which I named msbuild) to test:

#include <Windows.h>
#include <stdio.h>

main()
{
    printf("{%s}\n", GetCommandLine());
    return 0;
}

Using that I tested your variants:

cmd "msbuild a.sln /p:Configuration=Debug /p:Platform=\"Any CPU\""
{"msbuild" "a.sln" "/p:Configuration=Debug" "/p:Platform=\"Any" "CPU\""}
cmd "msbuild a.sln /p:Configuration=Debug" ["/p:Platform=\"Any CPU\""]
{"msbuild" "a.sln" "/p:Configuration=Debug" "/p:Platform=\"Any CPU\""}
cmd "msbuild" ["a.sln", "/p:Configuration=Debug", "/p:Platform=\"Any CPU\""]
{"msbuild" "a.sln" "/p:Configuration=Debug" "/p:Platform=\"Any CPU\""}

The one that fixes this is to use the Shell command, to tell Shake to avoid doing any of its own escaping:

cmd Shell "msbuild a.sln /p:Configuration=Debug /p:Platform=\"Any CPU\""
{msbuild  a.sln /p:Configuration=Debug /p:Platform="Any CPU"}

However, assuming the real msbuild is like the other Visual Studio tools (e.g. fsc, csc, cl), you can probably use the equivalent (and perhaps preferred) variant of:

msbuild a.sln /p:Configuration=Debug "/p:Platform=Any CPU"

Which you can express with Shake as:

cmd "msbuild a.sln /p:Configuration=Debug" ["/p:Platform=Any CPU"]
Neil Mitchell
  • 9,090
  • 1
  • 27
  • 85