forked from dotnet/dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ps1
126 lines (104 loc) · 3.44 KB
/
build.ps1
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
[CmdletBinding(PositionalBinding=$false)]
Param(
# Common settings
[switch][Alias('bl')]$binaryLog,
[string][Alias('c')]$configuration = "Release",
[string][Alias('v')]$verbosity = "minimal",
# Actions
[switch]$clean,
[switch]$sign,
[switch][Alias('h')]$help,
[switch][Alias('t')]$test,
# Advanced settings
[switch]$buildRepoTests,
[switch]$ci,
[switch][Alias('cwb')]$cleanWhileBuilding,
[switch][Alias('nobl')]$excludeCIBinarylog,
[switch] $prepareMachine,
[switch] $dev,
[Parameter(ValueFromRemainingArguments=$true)][String[]]$properties
)
function Get-Usage() {
Write-Host "Common settings:"
Write-Host " -binaryLog Output binary log (short: -bl)"
Write-Host " -configuration <value> Build configuration: 'Debug' or 'Release' (short: -c). [Default: Release]"
Write-Host " -verbosity <value> Msbuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic] (short: -v)"
Write-Host ""
Write-Host "Actions:"
Write-Host " -clean Clean the solution"
Write-Host " -sign Sign the build."
Write-Host " -help Print help and exit (short: -h)"
Write-Host " -test Run tests (repo tests omitted by default) (short: -t)"
Write-Host ""
Write-Host "Advanced settings:"
Write-Host " -buildRepoTests Build repository tests"
Write-Host " -ci Set when running on CI server"
Write-Host " -cleanWhileBuilding Cleans each repo after building (reduces disk space usage, short: -cwb)"
Write-Host " -excludeCIBinarylog Don't output binary log (short: -nobl)"
Write-Host " -prepareMachine Prepare machine for CI run, clean up processes after build"
Write-Host " -dev Use -dev or -ci versioning instead of .NET official build versions"
Write-Host ""
}
$useGlobalNuGetCache=$false
. $PSScriptRoot\common\tools.ps1
if ($help) {
Get-Usage
exit 0
}
$project = Join-Path $RepoRoot "build.proj"
$arguments = @()
$targets = "/t:Build"
# This repo uses the VSTest integration instead of the Arcade Test target
if ($test) {
$project = Join-Path (Join-Path $RepoRoot "test") "tests.proj"
$targets += ";VSTest"
# Workaround for vstest hangs (https://github.com/microsoft/vstest/issues/5091) [TODO]
$env:MSBUILDENSURESTDOUTFORTASKPROCESSES="1"
}
if ($sign) {
$arguments += "/p:Sign=true"
}
if ($buildRepoTests) {
$arguments += "/p:DotNetBuildTests=true"
}
if ($cleanWhileBuilding) {
$arguments += "/p:CleanWhileBuilding=true"
}
if ($dev) {
$arguments += "/p:UseOfficialBuildVersioning=false"
}
function Build {
InitializeToolset
# Manually unset NUGET_PACKAGES as InitializeToolset sets it unconditionally.
# The env var shouldn't be set so that the RestorePackagesPath msbuild property is respected.
$env:NUGET_PACKAGES=''
$bl = if ($binaryLog) { '/bl:' + (Join-Path $LogDir 'Build.binlog') } else { '' }
MSBuild -restore `
$project `
$bl `
$targets `
/p:Configuration=$configuration `
@properties `
@arguments
}
try {
if ($clean) {
if (Test-Path $ArtifactsDir) {
Remove-Item -Recurse -Force $ArtifactsDir
Write-Host 'Artifacts directory deleted.'
}
exit 0
}
if ($ci) {
if (-not $excludeCIBinarylog) {
$binaryLog = $true
}
}
Build
}
catch {
Write-Host $_.ScriptStackTrace
Write-PipelineTelemetryError -Category 'Build' -Message $_
ExitWithExitCode 1
}
ExitWithExitCode 0