Setting OctoPackNuGetProperties when calling msbuild from a powershell script

Similar to a problem that I saw for a user executing the msbuild from Nant but I’m using powershell (psake).

When calling msbuild I try to pass OctoPackNuGetProperties like so:

	& msbuild "$sln_file" `
		/p:Configuration=$configuration `
		/p:Platform="$platform" `
		/t:Build `
		/p:RunOctoPack=true `
		/p:DebugType=pdbonly `
		/p:OctoPackPackageVersion=$($versionNumbers.release) `
		"/p:OctoPackNuGetProperties=configuration=$configuration;builddate=$([System.DateTime]::Now.ToString())" `
		/p:OctoPackPublishPackageToFileShare=$build_dir

But only the first property ‘configuration’ is passed through. Can anyone help me figure out the correct syntax please? I’ve tried all sorts of variations without any success.

Thanks in advance.

Sorry. I meant to include the msbuild output too, here it is:

  OctoPack: Attempting to build package from 'WindowsService.nuspec'.
MSBUILD : OctoPack error OCTONUGET: Description is required. [C:\Solution\WindowsService\WindowsService.csproj]
MSBUILD : OctoPack error OCT-1805672349: There was an error calling NuGet. Please see the output above for more details. Command line: 'C:\Solution\packages\OctoPack.3.4.1\tools\NuGet.exe' pack "C:\Solution\WindowsService\obj\octopacking\WindowsService.nuspec"  -NoPackageAnalysis -BasePath "C:\Solution\WindowsService" -OutputDirectory "C:\Solution\WindowsService\obj\octopacked" -Version 1.0.0 -Properties "configuration=Release" [C:\Solution\WindowsService\WindowsService.csproj]
MSBUILD : OctoPack error OCT-1805672349: System.Exception: There was an error calling NuGet. Please see the output above for more details. Command line: 'C:\Solution\packages\OctoPack.3.4.1\tools\NuGet.exe' pack  "C:\Solution\WindowsService\obj\octopacking\WindowsService.nuspec"  -NoPackageAnalysis -BasePath "C:\Solution\WindowsService" -OutputDirectory "C:\Solution\WindowsService\obj\octopacked" -Version 1.0.0 -Properties "configuration=Release"\r [C:\Solution\WindowsService\WindowsService.csproj]
MSBUILD : OctoPack error OCT-1805672349:    at OctoPack.Tasks.CreateOctoPackPackage.RunNuGet(String specFilePath, String octopacking, String octopacked, String projectDirectory) in z:\BuildAgent\work\20ba9f2e0d5e4022\source\OctoPack.Task s\CreateOctoPackPackage.cs:line 588\r [C:\Solution\WindowsService\WindowsService.csproj]
MSBUILD : OctoPack error OCT-1805672349:    at OctoPack.Tasks.CreateOctoPackPackage.Execute() in z:\BuildAgent\work\20ba9f2e0d5e4022\source\OctoPack.Tasks\CreateOctoPackPackage.cs:line 202 [C:\Solution\WindowsService\WindowsService.csproj]

As can be seen by this only the first property is being passed to nuget and it is being truncated at the semi-colon.

Okay, I have a slightly unsatisfactory solution:

& msbuild "$sln_file" `
		/p:Configuration=$configuration `
		/p:Platform="$platform" `
		/t:Build `
		/p:RunOctoPack=true `
		/p:DebugType=pdbonly `
		/p:OctoPackPackageVersion=$($versionNumbers.release) `
		"/p:OctoPackNuGetProperties=`"configuration=$configuration;builddate=$([System.DateTime]::Now.ToString("yyyy-MM-dd_HH:mm:ss"))`"" `
		/p:OctoPackPublishPackageToFileShare=$build_dir

So I used escaped quote marks (using the back tick) to insert quotes around the properties I wanted to send. But I also had to format the date so as to remove the space character between the date and the time.

So it looks like I would have to quote the value in the quoted property value in the quoted command parameter if I wanted to pass a space!!! Yuk. And I haven’t worked out how to do that - using more PS escaped quotes hasn’t worked so far.

If there is a neater way please let me know.

Hi Robert,

Thanks for reaching out. Unfortunately due to the way Powershell works with single quotes, double quotes and variables, the way you described in your last comment is the only one I can think of to make it work.

Best regards,
Dalmiro