-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-release.ps1
More file actions
73 lines (62 loc) · 2.13 KB
/
build-release.ps1
File metadata and controls
73 lines (62 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
param(
[ValidateSet("Debug", "Release")]
[string]$Configuration = "Release",
[switch]$NoRestore
)
$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
function Wait-ForKeyPress {
Write-Host ""
Write-Host "Press any key to close..." -ForegroundColor DarkGray
if ($Host.UI.RawUI) {
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
else {
[void](Read-Host)
}
}
try {
$scriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $scriptRoot
$solution = Get-ChildItem -Path $scriptRoot -Filter *.slnx -File | Select-Object -First 1
if (-not $solution) {
$solution = Get-ChildItem -Path $scriptRoot -Filter *.sln -File | Select-Object -First 1
}
if (-not $solution) {
throw "Could not find a solution file (*.slnx or *.sln) in $scriptRoot"
}
Write-Host "Using solution: $($solution.Name)" -ForegroundColor Cyan
Write-Host "Removing stale build folders..." -ForegroundColor Cyan
Get-ChildItem -Path $scriptRoot -Directory -Recurse -Force |
Where-Object { $_.Name -in @("bin", "obj") } |
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
if (-not $NoRestore) {
Write-Host "Restoring..." -ForegroundColor Cyan
dotnet restore $solution.FullName
if ($LASTEXITCODE -ne 0) {
throw "dotnet restore failed with exit code $LASTEXITCODE"
}
}
Write-Host "Cleaning ($Configuration)..." -ForegroundColor Cyan
dotnet clean $solution.FullName -c $Configuration
if ($LASTEXITCODE -ne 0) {
throw "dotnet clean failed with exit code $LASTEXITCODE"
}
Write-Host "Building ($Configuration)..." -ForegroundColor Cyan
$buildArgs = @("build", $solution.FullName, "-c", $Configuration)
if ($NoRestore) {
$buildArgs += "--no-restore"
}
& dotnet @buildArgs
if ($LASTEXITCODE -ne 0) {
throw "dotnet build failed with exit code $LASTEXITCODE"
}
Write-Host "Done." -ForegroundColor Green
}
catch {
Write-Host "Build failed: $($_.Exception.Message)" -ForegroundColor Red
throw
}
finally {
Wait-ForKeyPress
}