Related question here.
This works properly for compiling an mvc3 application.
task Compile
{
$config = $script:siteConfig.config
exec { & "C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe" $webproject_path `
/p:Configuration=$config /p:WebProjectOutputDir="$publish_dir" `
/p:Outdir="$out_dir" /p:CleanWebProjectOutputDir=False `
/T:_WPPCopyWebApplication /T:ResolveReferences /verbosity:quiet /nologo }
}
All of those path variables are script properties. However, when spaces are introduced in those calculated paths (e.g. the project is moved from C:\Projects\ to C:\Users\ASDFG1\Documents\Visual Studio 2010\Projects) msbuild thinks there's multiple project files. This makes sense but I have to be missing something, getting a parsed variable into quotes shouldn't be this hard.
Variations tried
exec { Invoke-Expression "& C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe '$webproject_path' /p:Configuration=$config /p:WebProjectOutputDir='$publish_dir' /p:Outdir='$out_dir' /p:CleanWebProjectOutputDir=False /T:_WPPCopyWebApplication /T:ResolveReferences /verbosity:quiet /nologo" }
exec { C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe "`"$webproject_path`"" `
/p:Configuration=$config /p:WebProjectOutputDir="`"$publish_dir`"" `
/p:Outdir="`"$out_dir`"" /p:CleanWebProjectOutputDir=False `
/T:_WPPCopyWebApplication /T:ResolveReferences /verbosity:quiet /nologo }
Invoke-Expression
sneaks in. The point is that Invoke-Expression doesn't change anything about how the command is run, it just adds a layer of indirection that incurs its own problems sometimes. Unless you're really building a PowerShell command at runtime to execute, Invoke-Expression is best avoided. – Activator