How to output /p:Platform="Any CPU" as quoted from shake cmd?

738 Views Asked by At

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.

1

There are 1 best solutions below

0
On BEST ANSWER

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"]