|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | + Generates the NuGet packages (including the symbols). |
| 4 | + A clean build is performed the packaging. |
| 5 | +.PARAMETER commitSha |
| 6 | + The LibGit2Sharp commit sha that contains the version of the source code being packaged. |
| 7 | +#> |
| 8 | + |
| 9 | +Param( |
| 10 | + [Parameter(Mandatory=$true)] |
| 11 | + [string]$commitSha |
| 12 | +) |
| 13 | + |
| 14 | +$ErrorActionPreference = "Stop" |
| 15 | +Set-StrictMode -Version Latest |
| 16 | + |
| 17 | +function Run-Command([scriptblock]$Command) { |
| 18 | + $output = "" |
| 19 | + |
| 20 | + $exitCode = 0 |
| 21 | + $global:lastexitcode = 0 |
| 22 | + |
| 23 | + & $Command |
| 24 | + |
| 25 | + if ($LastExitCode -ne 0) { |
| 26 | + $exitCode = $LastExitCode |
| 27 | + } elseif (!$?) { |
| 28 | + $exitCode = 1 |
| 29 | + } else { |
| 30 | + return |
| 31 | + } |
| 32 | + |
| 33 | + $error = "``$Command`` failed" |
| 34 | + |
| 35 | + if ($output) { |
| 36 | + Write-Host -ForegroundColor "Red" $output |
| 37 | + $error += ". See output above." |
| 38 | + } |
| 39 | + |
| 40 | + Throw $error |
| 41 | +} |
| 42 | + |
| 43 | +function Clean-OutputFolder($folder) { |
| 44 | + |
| 45 | + If (Test-Path $folder) { |
| 46 | + Write-Host -ForegroundColor "Green" "Dropping `"$folder`" folder..." |
| 47 | + |
| 48 | + Run-Command { & Remove-Item -Recurse -Force "$folder" } |
| 49 | + |
| 50 | + Write-Host "Done." |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +################# |
| 55 | + |
| 56 | +$root = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition |
| 57 | +$projectPath = Join-Path $root "..\LibGit2Sharp" |
| 58 | + |
| 59 | +Remove-Item (Join-Path $projectPath "*.nupkg") |
| 60 | + |
| 61 | +Clean-OutputFolder (Join-Path $projectPath "bin\") |
| 62 | +Clean-OutputFolder (Join-Path $projectPath "obj\") |
| 63 | + |
| 64 | +# The nuspec file needs to be next to the csproj, so copy it there during the pack operation |
| 65 | +Copy-Item (Join-Path $root "LibGit2Sharp.nuspec") $projectPath |
| 66 | + |
| 67 | +Push-Location $projectPath |
| 68 | + |
| 69 | +try { |
| 70 | + Set-Content -Encoding ASCII $(Join-Path $projectPath "libgit2sharp_hash.txt") $commitSha |
| 71 | + Run-Command { & "$(Join-Path $projectPath "..\Lib\NuGet\Nuget.exe")" Restore "$(Join-Path $projectPath "..\LibGit2Sharp.sln")" } |
| 72 | + |
| 73 | + # Cf. https://stackoverflow.com/questions/21728450/nuget-exclude-files-from-symbols-package-in-nuspec |
| 74 | + Run-Command { & "$(Join-Path $projectPath "..\Lib\NuGet\Nuget.exe")" Pack -Build -Symbols "$(Join-Path $projectPath "LibGit2Sharp.csproj")" -Prop Configuration=Release -Exclude "**/NativeBinaries/**/*.*"} |
| 75 | + Run-Command { & "$(Join-Path $projectPath "..\Lib\NuGet\Nuget.exe")" Pack "$(Join-Path $projectPath "LibGit2Sharp.csproj")" -Prop Configuration=Release } |
| 76 | +} |
| 77 | +finally { |
| 78 | + Pop-Location |
| 79 | + Remove-Item (Join-Path $projectPath "LibGit2Sharp.nuspec") |
| 80 | + Set-Content -Encoding ASCII $(Join-Path $projectPath "libgit2sharp_hash.txt") "unknown" |
| 81 | +} |
0 commit comments