forked from dotnet/corefx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ps1
114 lines (102 loc) · 4.88 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
[CmdletBinding(PositionalBinding=$false)]
Param(
[switch][Alias('b')]$build,
[switch][Alias('t')]$test,
[switch] $buildtests,
[string][Alias('c')]$configuration = "Debug",
[string][Alias('f')]$framework,
[string] $os,
[switch] $allconfigurations,
[switch] $coverage,
[string] $testscope,
[string] $arch,
[switch] $clean,
[Parameter(ValueFromRemainingArguments=$true)][String[]]$properties
)
function Get-Help() {
Write-Host "Common settings:"
Write-Host " -framework Build framework: netcoreapp, netfx, uap (short: -f)"
Write-Host " -configuration <value> Build configuration: Debug or Release (short: -c)"
Write-Host " -verbosity <value> MSBuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic] (short: -v)"
Write-Host " -binaryLog Output binary log (short: -bl)"
Write-Host " -help Print help and exit (short: -h)"
Write-Host ""
Write-Host "Actions (defaults to -restore -build):"
Write-Host " -restore Restore dependencies (short: -r)"
Write-Host " -build Build all source projects (short: -b)"
Write-Host " -buildtests Build all test projects"
Write-Host " -rebuild Rebuild all source projects"
Write-Host " -test Run all unit tests (short: -t)"
Write-Host " -pack Package build outputs into NuGet packages"
Write-Host " -sign Sign build outputs"
Write-Host " -publish Publish artifacts (e.g. symbols)"
Write-Host " -clean Clean the solution"
Write-Host ""
Write-Host "Advanced settings:"
Write-Host " -coverage Collect code coverage when testing"
Write-Host " -testscope Scope tests, allowed values: innerloop, outerloop, all"
Write-Host " -allconfigurations Build packages for all build configurations"
Write-Host " -os Build operating system: Windows_NT or Unix"
Write-Host " -arch Build platform: x86, x64, arm or arm64"
Write-Host " -msbuildEngine <value> MSBuild engine to use: dotnet or vs"
Write-Host ""
Write-Host "Command-line arguments not listed above are passed thru to msbuild."
Write-Host "The above arguments can be shortened as much as to be unambiguous (e.g. -con for configuration, -t for test, etc.)."
}
# Exit if script has been dot-sourced
if ($MyInvocation.InvocationName -eq ".") {
exit 0
}
# Check if an action is passed in
$actions = "r","restore","b","build","rebuild","deploy","deployDeps","test","integrationTest","sign","publish","buildtests"
$actionPassedIn = @(Compare-Object -ReferenceObject @($PSBoundParameters.Keys) -DifferenceObject $actions -ExcludeDifferent -IncludeEqual).Length -ne 0
if ($null -ne $properties -and $actionPassedIn -ne $true) {
$actionPassedIn = @(Compare-Object -ReferenceObject $properties -DifferenceObject $actions.ForEach({ "-" + $_ }) -ExcludeDifferent -IncludeEqual).Length -ne 0
}
if ($clean) {
$artifactsPath = "$PSScriptRoot\..\artifacts"
if(Test-Path $artifactsPath) {
Remove-Item -Recurse -Force $artifactsPath
Write-Host "Artifacts directory deleted."
}
if (!$actionPassedIn) {
exit 0
}
}
if (!$actionPassedIn) {
$arguments = "-restore -build"
}
$possibleDirToBuild = if($properties.Length -gt 0) { $properties[0]; } else { $null }
if ($null -ne $possibleDirToBuild) {
$dtb = $possibleDirToBuild.TrimEnd('\')
if (Test-Path $dtb) {
$properties[0] = "/p:DirectoryToBuild=$(Resolve-Path $dtb)"
}
else {
$dtb = Join-Path "$PSSCriptRoot\..\src" $dtb
if (Test-Path $dtb) {
$properties[0] = "/p:DirectoryToBuild=$(Resolve-Path $dtb)"
}
}
}
foreach ($argument in $PSBoundParameters.Keys)
{
switch($argument)
{
"build" { $arguments += " -build" }
"test" { $arguments += " -test" }
"buildtests" { $arguments += " /p:BuildTests=true" }
"clean" { }
"configuration" { $configuration = (Get-Culture).TextInfo.ToTitleCase($($PSBoundParameters[$argument])); $arguments += " /p:ConfigurationGroup=$configuration -configuration $configuration" }
"framework" { $arguments += " /p:TargetGroup=$($PSBoundParameters[$argument].ToLowerInvariant())"}
"os" { $arguments += " /p:OSGroup=$($PSBoundParameters[$argument])" }
"allconfigurations" { $arguments += " /p:BuildAllConfigurations=true" }
"coverage" { $arguments += " /p:Coverage=true" }
"testscope" { $arguments += " /p:TestScope=$($PSBoundParameters[$argument])" }
"arch" { $arguments += " /p:ArchGroup=$($PSBoundParameters[$argument])" }
"properties" { $arguments += " " + $properties }
default { $arguments += " /p:$argument=$($PSBoundParameters[$argument])" }
}
}
Invoke-Expression "& `"$PSScriptRoot/common/build.ps1`" $arguments"
exit $lastExitCode