2

I'm trying to execute a simple command with path containing spaces

$solution = "test.sln"
$msbuild = "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe"
Exec { iex "$msbuild `"$solution`" /t:clean"}
Exec { iex "$msbuild `"$solution`"" }

This throws an error

Exception: The term 'x86' is not recognized as the name

which seems to be because the $msbuild command isn't properly quoted. Tried quoting the command (and escaping quotes with backticks) but still no luck

$msbuild   = "`"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe`""

How can you correctly escape/quote above? What are the escaping rules in Powershell?

2
  • 1
    I'm not familiar with "exec"; is it a custom function? What does it do?
    – BHall
    Feb 3, 2016 at 5:59
  • Yes, it's a custom function (I'm not sure what it does though). I assume it executes the commands within the brackets.
    – ubi
    Feb 4, 2016 at 3:48

2 Answers 2

3
$msbuild = "${env:ProgramFiles(x86)}" + '\MSBuild\14.0\Bin\MSBuild.exe'

Try this way. No spaces, so path should be fine.

2

Perhaps try using the the Call operator (&) instead of invoke-expression? I'm not sure how any output will be processed though.

$solution = "test.sln"
$msbuild = "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe"
Exec { & $msbuild $solution /t:clean}
Exec { & $msbuild $solution }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .