I've just tested this on PowerShell v1.0. Setup is as follows:
Id CommandLine -- ----------- 1 $msbuild = "C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe" 4 $a = "C:\some\project\or\other\src\Solution.sln /target:Clean /target:Build"
.
This line fails with an unintuitive error message:
Id CommandLine -- ----------- 5 & $msbuild $a
.
This line fails because & expects the first argument to be the command itself.
Id CommandLine -- ----------- 10 & "$msbuild $a"
.
This line works:
Id CommandLine -- ----------- 16 cmd /c "$msbuild $a"
.
Please explain. I'm more interested in why the & syntax isn't working, than an MSBuild-specific workaround.
To run MSBuild at a command prompt, pass a project file to MSBuild.exe, together with the appropriate command-line options. Command-line options let you set properties, execute specific targets, and set other options that control the build process.
Click Start, type PowerShell, and then click Windows PowerShell. From the Start menu, click Start, click All Programs, click Accessories, click the Windows PowerShell folder, and then click Windows PowerShell.
Builds the targets in the project file that you specify. If you don't specify a project file, MSBuild searches the current working directory for a file name extension that ends in proj and uses that file. You can also specify a Visual Studio solution file for this argument.
Ugh.
$collectionOfArgs = @("C:\some\project\or\other\src\Solution.sln", "/target:Clean", "/target:Build") & $msbuild $collectionOfArgs
This works. & takes a collection of arguments, so you must split up strings containing multiple arguments into a collection of string arguments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With