This repository was archived by the owner on Apr 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbuild.ps1
73 lines (63 loc) · 1.97 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
param (
[switch]$Debug,
[string]$VisualStudioVersion = '15.0',
[string]$Verbosity = 'minimal',
[string]$Logger,
[switch]$Incremental
)
# build the solution
$SolutionPath = "..\PublicApiAnalyzer.sln"
# make sure the script was run from the expected path
if (!(Test-Path $SolutionPath)) {
$host.ui.WriteErrorLine('The script was run from an invalid working directory.')
exit 1
}
If ($Debug) {
$BuildConfig = 'Debug'
} Else {
$BuildConfig = 'Release'
}
# download NuGet.exe if necessary
$nuget = '..\.nuget\NuGet.exe'
If (-not (Test-Path $nuget)) {
If (-not (Test-Path '..\.nuget')) {
mkdir '..\.nuget'
}
$nugetSource = 'https://dist.nuget.org/win-x86-commandline/latest/nuget.exe'
Invoke-WebRequest $nugetSource -OutFile $nuget
If (-not $?) {
$host.ui.WriteErrorLine('Unable to download NuGet executable, aborting!')
exit $LASTEXITCODE
}
}
# build the main project
$visualStudio = (Get-ItemProperty 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\SxS\VS7')."$VisualStudioVersion"
$msbuild = "$visualStudio\MSBuild\$VisualStudioVersion\Bin\MSBuild.exe"
If (-not (Test-Path $msbuild)) {
$host.UI.WriteErrorLine("Couldn't find MSBuild.exe")
exit 1
}
# Attempt to restore packages up to 3 times, to improve resiliency to connection timeouts and access denied errors.
$maxAttempts = 3
For ($attempt = 0; $attempt -lt $maxAttempts; $attempt++) {
&$nuget 'restore' $SolutionPath
If ($?) {
Break
} ElseIf (($attempt + 1) -eq $maxAttempts) {
$host.ui.WriteErrorLine('Failed to restore required NuGet packages, aborting!')
exit $LASTEXITCODE
}
}
If ($Logger) {
$LoggerArgument = "/logger:$Logger"
}
If ($Incremental) {
$Target = 'build'
} Else {
$Target = 'rebuild'
}
&$msbuild '/nologo' '/m' '/nr:false' "/t:$Target" $LoggerArgument "/verbosity:$Verbosity" "/p:Configuration=$BuildConfig" "/p:VisualStudioVersion=$VisualStudioVersion" "/p:KeyConfiguration=$KeyConfiguration" $SolutionPath
If (-not $?) {
$host.ui.WriteErrorLine('Build failed, aborting!')
exit $LASTEXITCODE
}