I've not played with Squirrel, so this may not work; but too much code here to just submit as a comment...
Try this:
Write-Host "Current Path $env:Agent_BuildDirectory"
Write-Host "Build Number $env:Build_BuildNumber"
$squirrel = Get-Item (Join-Path $env:BUILD_SOURCESDIRECTORY "packages\squirrel.windows.*\tools\Squirrel.exe") | select -First 1 -Expand FullName
$releaseDir = '.\Releases'
$nugetPackFile = ".\MyApp\MyApp.$env:Build_BuildNumber.nupkg"
Write-Host $squirrel
Write-Host $nugetPackFile
if((Test-Path $nugetPackFile) -and (Test-Path $squirrel)) {
$squirrelArg1 = "--releasify=`"$nugetPackFile`""
$squirrelArg2 = "--releaseDir=`"$releaseDir`""
& $squirrel $squirrelArg1 $squirrelArg2
}
Getting Squirrel.exe Path
(Join-Path $env:BUILD_SOURCESDIRECTORY "packages\squirrel.windows.*\tools\Squirrel.exe")
- here I use Join-Path
to avoid any issues around whether or not the value of $env:BUILD_SOURCESDIRECTORY
ends in a backslash.
Get-Item
- I put this before that path so that it will resolve the path to a valid path (i.e. working out any matches of the asterisk/wildcard).
| select -First 1 -Expand FullName
I then add this to get the first path which matches the result, and to return the full file path to squirrel.exe
Passing Parameters
For the statements below, I added double quotes around the paths; sometimes this is required to clarify which argument they relate to; particularly if there are any spaces or special characters in the paths. I also switched from using +
to putting the variable within double quotes as this makes it simpler to concatenate the quotes within the string. I used backticks on the quotes in the string to escape those characters.
$squirrelArg1 = "--releasify=`"$nugetPackFile`""
$squirrelArg2 = "--releaseDir=`"$releaseDir`""
Hope that helps, but sadly this is very much guesswork by me; sorry.
Update
Getting the latest version; assuming asterisk in the path packages\squirrel.windows.*\tools\Squirrel.exe
represents the version number in the form: Major
.Minor
.Build
.
$squirrel = Get-Item (Join-Path $env:BUILD_SOURCESDIRECTORY "packages\squirrel.windows.*\tools\Squirrel.exe") | %{
if ($_ -match '.*\\squirrel\.windows\.(?<Major>\d+)\.(?<Minor>\d+)\.(?<Build>\d+)\\tools\\Squirrel\.exe') {
(new-object -TypeName PSObject -Property $matches)
}
} | sort @{e={$_.Major};a=0}, @{e={$_.Minor};a=0}, @{e={$_.Build};a=0} | select -First 1 -ExpandProperty '0'