Squirrel Powershell文件未创建Setup.exe

时间:2017-02-09 21:26:04

标签: c# powershell continuous-delivery squirrel.windows

我在构建服务器上运行以下PowerShell脚本

Write-Host "Current Path  $env:Agent_BuildDirectory"
Write-Host "Build Number  $env:Build_BuildNumber"
$squirrel = "$env:BUILD_SOURCESDIRECTORY\packages\squirrel.windows.*\tools\Squirrel.exe"
$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 
}

它会运行,并且只会在nupkg文件夹中创建.\Releases。如果我在构建服务器代理上的Visual Studio实例中运行相同的--releasify命令,则会创建所有setup.exeReleases文件。为什么此PowerShell脚本的工作方式与VS中NuGet PowerShell窗口中运行的命令不同?

2 个答案:

答案 0 :(得分:2)

我没有玩松鼠,所以这可能行不通;但这里的代码太多,只能作为评论提交......

试试这个:

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 
}

获取Squirrel.exe路径

  • (Join-Path $env:BUILD_SOURCESDIRECTORY "packages\squirrel.windows.*\tools\Squirrel.exe") - 此处我使用Join-Path来避免$env:BUILD_SOURCESDIRECTORY的值是否以反斜杠结尾的任何问题。
  • Get-Item - 我把它放在该路径之前,以便它将解析到有效路径的路径(即计算出星号/通配符的任何匹配项。)
  • | select -First 1 -Expand FullName然后我添加此内容以获取与结果匹配的第一个路径,并将完整文件路径返回到squirrel.exe

传递参数

对于下面的陈述,我在路径周围添加了双引号;有时这需要澄清它们与之相关的论点;特别是如果路径中有任何空格或特殊字符。我也从使用+转换为将变量放在双引号内,因为这样可以更简单地连接字符串中的引号。我在字符串中的引号上使用了反引号以逃避这些字符。

  • $squirrelArg1 = "--releasify=`"$nugetPackFile`""
  • $squirrelArg2 = "--releaseDir=`"$releaseDir`""

希望有所帮助,但遗憾的是,这是我的猜测;遗憾。

<强>更新

获取最新版本;假设路径packages\squirrel.windows.*\tools\Squirrel.exe中的星号代表表单中的版本号:MajorMinorBuild

$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'

答案 1 :(得分:0)

我找到了答案here

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") | %{
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'

Set-Alias Squirrel $squirrel

$releaseDir = '.\Releases'
$nugetPackFile = ".\MyApp\MyApp.$env:Build_BuildNumber.nupkg"
Write-Host $squirrel
Write-Host $nugetPackFile

if((Test-Path $nugetPackFile) -and (Test-Path $squirrel)) {
    Squirrel --releasify $nugetPackFile --releaseDir $releaseDir | Write-Output
}

非常感谢@JohnLBevan帮助修复我的PowerShell代码。