Cake: Build fails on certain MSBuild commands from folder with spaces - "Only one project can be specified"

Created on 30 Dec 2016  路  4Comments  路  Source: cake-build/cake

What You Are Seeing?

Calling certain MSBuild commands that receive a project sends a switch with no escaped spaces or special characters, causing MSBuild to fail.

What is Expected?

Successful building! :)

What version of Cake are you using?

0.15.2

Are you running on a 32 or 64 bit system?

64-bit

What environment are you running on? Windows? Linux? Mac?

Windows

Are you running on a CI Server? If so, which one?

Nope, local.

How Did You Get This To Happen? (Steps to Reproduce)

  1. Created a build script to build a series of C# Solutions and Projects.
  2. Script executes correctly
  3. Try to compile on a machine where the solutions' path includes a space, and compilation fails on the project, with the MSBuild message "Only one project can be specified"

Code excerpt at https://gist.github.com/josemaia/b5ceede38cc3e72e0a61f610b52c9e36

The failure is on l. 44 (see Output log).

When investigating the issue, I detected a series of StackOverflow and similar questions where this happens via the command line, however, I could not manipulate the way Cake sends its parameters to MSBuild. See: http://stackoverflow.com/questions/16979137/msbuild-error-msb1008-only-one-project-can-be-specified-in-teamcity or http://stackoverflow.com/questions/3779701/msbuild-error-msb1008-only-one-project-can-be-specified.

Output Log

https://gist.github.com/josemaia/d2d27396c313aac0bc9c1d56b68fae24

Most helpful comment

Try .WithProperty("PackageLocation", new string[]{packagesDir.ToString().Quote() })

All 4 comments

@josemaia聽Have you tried to聽quote the PackageLocation property? It looks like this at the moment: /p:PackageLocation=E:\um teste\DEV\build-package\Release

As shown in the code sample, I am doing this to add the property to the MSBuild object:

    .WithProperty("PackageLocation", new string[]{packagesDir.ToString()  })

Is there any way I could ensure this is quoted? I attempted to insert ' and " in several places, but it did not work as desired.

Try .WithProperty("PackageLocation", new string[]{packagesDir.ToString().Quote() })

Looks like the .Quote() method did it!

I was unaware it existed, thank you.

Was this page helpful?
0 / 5 - 0 ratings