|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | + You can add this to you build script to ensure that psbuild is available before calling |
| 4 | + Invoke-MSBuild. If psbuild is not available locally it will be downloaded automatically. |
| 5 | +#> |
| 6 | +function EnsurePsbuildInstalled{ |
| 7 | + [cmdletbinding()] |
| 8 | + param( |
| 9 | + [string]$psbuildInstallUri = 'https://raw.githubusercontent.com/ligershark/psbuild/master/src/GetPSBuild.ps1' |
| 10 | + ) |
| 11 | + process{ |
| 12 | + if(-not (Get-Command "Invoke-MsBuild" -errorAction SilentlyContinue)){ |
| 13 | + 'Installing psbuild from [{0}]' -f $psbuildInstallUri | Write-Verbose |
| 14 | + (new-object Net.WebClient).DownloadString($psbuildInstallUri) | iex |
| 15 | + } |
| 16 | + else{ |
| 17 | + 'psbuild already loaded, skipping download' | Write-Verbose |
| 18 | + } |
| 19 | + |
| 20 | + # make sure it's loaded and throw if not |
| 21 | + if(-not (Get-Command "Invoke-MsBuild" -errorAction SilentlyContinue)){ |
| 22 | + throw ('Unable to install/load psbuild from [{0}]' -f $psbuildInstallUri) |
| 23 | + } |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +# Taken from psake https://github.com/psake/psake |
| 28 | + |
| 29 | +<# |
| 30 | +.SYNOPSIS |
| 31 | + This is a helper function that runs a scriptblock and checks the PS variable $lastexitcode |
| 32 | + to see if an error occcured. If an error is detected then an exception is thrown. |
| 33 | + This function allows you to run command-line programs without having to |
| 34 | + explicitly check the $lastexitcode variable. |
| 35 | +.EXAMPLE |
| 36 | + exec { svn info $repository_trunk } "Error executing SVN. Please verify SVN command-line client is installed" |
| 37 | +#> |
| 38 | +function Exec |
| 39 | +{ |
| 40 | + [CmdletBinding()] |
| 41 | + param( |
| 42 | + [Parameter(Position=0,Mandatory=1)][scriptblock]$cmd, |
| 43 | + [Parameter(Position=1,Mandatory=0)][string]$errorMessage = ($msgs.error_bad_command -f $cmd) |
| 44 | + ) |
| 45 | + & $cmd |
| 46 | + if ($lastexitcode -ne 0) { |
| 47 | + throw ("Exec: " + $errorMessage) |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +if(Test-Path .\artifacts) { Remove-Item .\artifacts -Force -Recurse } |
| 52 | + |
| 53 | +EnsurePsbuildInstalled |
| 54 | + |
| 55 | +exec { & dotnet restore } |
| 56 | + |
| 57 | +Invoke-MSBuild |
| 58 | + |
| 59 | +$revision = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = 1 }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL]; |
| 60 | +$revision = "{0:D4}" -f [convert]::ToInt32($revision, 10) |
| 61 | + |
| 62 | +exec { & dotnet pack .\src\GravatarTagHelpers -c Release -o .\artifacts --version-suffix=$revision } |
| 63 | + |
| 64 | + |
0 commit comments