-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
153 lines (136 loc) · 4.13 KB
/
build.ps1
File metadata and controls
153 lines (136 loc) · 4.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<#
.SYNOPSIS
Builds the software and examples.
.DESCRIPTION
Builds the software with various settings and options.
.PARAMETER Configuration
Specifies to build in Release configuration. Default is buildign for 'Debug'.
.PARAMETER Example
Run example, implies building the software.
.PARAMETER Test
Run tests, implies building the software.
.PARAMETER Clean
Don't build, but just clean build artifacts.
.PARAMETER Tidy
Don't build, but just clean the working copy from intermediate files.
.PARAMETER Build
Explicitly specify to build the software. Use together with '-Tidy' or '-Clean'.
.PARAMETER Arguments
Additional arguments to pass directly to 'dotnet.exe build' invocations.
#>
[CmdletBinding(PositionalBinding = $false)]
param(
[string]$Configuration = 'Debug',
[switch]$Tidy = $false,
[switch]$Clean = $false,
[switch]$Test = $false,
[switch]$Example = $false,
[switch]$Build = $false,
[switch]$Loop = $false,
[Parameter(ValueFromRemainingArguments = $true)][string[]]$Arguments
)
$ErrorActionPreference = 'Stop';
function Write-Status($text) { Write-Host -ForegroundColor DarkCyan -BackgroundColor White $text }
function Write-Fail($text) { Write-Host -ForegroundColor Red $text }
function Exit-IfCommandError($action) {
if ($LASTEXITCODE -ne 0) {
Write-Fail "$action failed with code $LASTEXITCODE."
Exit $LASTEXITCODE
}
}
$LocalPackages = $PSScriptRoot + '\pkgs'
$LocalRestorePath = $PSScriptRoot + '\example\Packages'
$Locations = @('src', 'example')
if ($Loop) {
$Tidy = $true
$Build = $true
$Test = $true
$Example = $true
}
# -----------------------------------------------------------------------------
# Clean / Tidy
# -----------------------------------------------------------------------------
if ($Tidy) {
$Clean = $true
}
if ($Tidy) {
Write-Status "Tidy"
Write-Host "Cleaning bin/ and obj/ folders"
foreach ($location in $Locations) {
Get-ChildItem -Path $location -Include bin, obj -Recurse -Directory | ForEach-Object {
Remove-Item "$($_.FullName)\*" -Recurse -Force -ErrorAction Continue
}
}
Write-Host "Removing local packages from $LocalPackages"
if (Test-Path "$LocalPackages") {
Remove-Item "$LocalPackages\*.nupkg" -Force -ErrorAction Continue
}
Write-Host "Removing local restore cache from $LocalRestorePath"
if (Test-Path "$LocalRestorePath") {
Remove-Item "$LocalRestorePath\*" -Recurse -Force -ErrorAction Continue
}
Write-Host "Removing build logs"
foreach ($location in $Locations) {
Remove-Item "$PSScriptRoot\msbuild.$location.binlog" -Force -ErrorAction Continue 2> $null
}
}
if ($Clean) {
foreach ($location in $Locations) {
Write-Status "Cleaning $location"
Push-Location $location
try {
dotnet clean --nologo --configuration $Configuration -v m
Exit-IfCommandError "Clean"
}
finally {
Pop-Location
}
}
}
if (($Clean -or $Tidy) -And !$Build) {
Exit 0
}
# -----------------------------------------------------------------------------
# Build
# -----------------------------------------------------------------------------
foreach ($location in $Locations) {
Write-Status "Building $location"
Push-Location $location
try {
dotnet restore
Exit-IfCommandError "Restore"
dotnet build --nologo --configuration $Configuration `
/binaryLogger:"$PSScriptRoot\msbuild.$location.binlog;ProjectImports=Embed" `
$Arguments
Exit-IfCommandError "Build"
}
finally {
Pop-Location
}
}
# -----------------------------------------------------------------------------
# Test
# -----------------------------------------------------------------------------
if ($Test) {
Write-Status "Test"
Push-Location $PSScriptRoot\src
try {
dotnet test
Exit-IfCommandError "Test"
} finally {
Pop-Location
}
}
# -----------------------------------------------------------------------------
# Example
# -----------------------------------------------------------------------------
if ($Example) {
Write-Status "Example"
Push-Location $PSScriptRoot\example\SampleHost
try {
dotnet run --configuration $Configuration
Exit-IfCommandError "Run Example"
} finally {
Pop-Location
}
}