This repository has been archived by the owner on Nov 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathbuild.ps1
117 lines (99 loc) · 3.66 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
param (
[switch]$Debug,
[string]$VisualStudioVersion = '15.0',
[switch]$SkipKeyCheck,
[string]$Verbosity = 'minimal',
[string]$Logger,
[switch]$Incremental
)
# build the solution
$SolutionPath = "..\AsyncUsageAnalyzers.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
}
. .\version.ps1
If ($Debug) {
$BuildConfig = 'Debug'
} Else {
$BuildConfig = 'Release'
}
If ($Version.Contains('-')) {
$KeyConfiguration = 'Dev'
} Else {
$KeyConfiguration = 'Final'
}
# 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
}
if ($Incremental) {
# Skip NuGet validation and copying packages to the output directory
exit 0
}
# By default, do not create a NuGet package unless the expected strong name key files were used
if (-not $SkipKeyCheck) {
. .\keys.ps1
foreach ($pair in $Keys.GetEnumerator()) {
$assembly = Resolve-FullPath -Path "..\AsyncUsageAnalyzers\AsyncUsageAnalyzers.CodeFixes\bin\$BuildConfig\$($pair.Key)\AsyncUsageAnalyzers.dll"
# Run the actual check in a separate process or the current process will keep the assembly file locked
powershell -Command ".\check-key.ps1 -Assembly '$assembly' -ExpectedKey '$($pair.Value)' -Build '$($pair.Key)'"
If (-not $?) {
$host.ui.WriteErrorLine('Failed to verify strong name key for build, aborting!')
exit $LASTEXITCODE
}
$assembly = Resolve-FullPath -Path "..\AsyncUsageAnalyzers\AsyncUsageAnalyzers.CodeFixes\bin\$BuildConfig\$($pair.Key)\AsyncUsageAnalyzers.CodeFixes.dll"
# Run the actual check in a separate process or the current process will keep the assembly file locked
powershell -Command ".\check-key.ps1 -Assembly '$assembly' -ExpectedKey '$($pair.Value)' -Build '$($pair.Key)'"
If (-not $?) {
$host.ui.WriteErrorLine('Failed to verify strong name key for build, aborting!')
exit $LASTEXITCODE
}
}
}
if (-not (Test-Path 'nuget')) {
mkdir "nuget"
}
Copy-Item "..\AsyncUsageAnalyzers\AsyncUsageAnalyzers.CodeFixes\bin\$BuildConfig\AsyncUsageAnalyzers.$Version.nupkg" 'nuget'
Copy-Item "..\AsyncUsageAnalyzers\AsyncUsageAnalyzers.CodeFixes\bin\$BuildConfig\AsyncUsageAnalyzers.$Version.symbols.nupkg" 'nuget'