-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.ps1
More file actions
297 lines (235 loc) · 10 KB
/
build.ps1
File metadata and controls
297 lines (235 loc) · 10 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# original: https://gist.github.com/peters/6812859/raw/a965bdb5ae39dbff351420da64df4e9925e07e36/Build.ps1
param(
[string]$packageVersion = $null,
[string]$config = "Release",
[string[]]$targetFrameworks = @("v4.5"),
[string[]]$platforms = @("AnyCpu"),
[ValidateSet("rebuild", "build")]
[string]$target = "rebuild",
[ValidateSet("quiet", "minimal", "normal", "detailed", "diagnostic")]
[string]$verbosity = "minimal",
[bool]$alwaysClean = $true
)
# Diagnostic
function Write-Diagnostic {
param([string]$message)
Write-Host
Write-Host $message -ForegroundColor Green
Write-Host
}
function Die([string]$message, [object[]]$output) {
if ($output) {
Write-Output $output
$message += ". See output above."
}
Write-Error $message
exit 1
}
function Create-Folder-Safe {
param(
[string]$folder = $(throw "-folder is required.")
)
if(-not (Test-Path $folder)) {
[System.IO.Directory]::CreateDirectory($folder)
}
}
# Build
function Build-Clean {
param(
[string]$rootFolder = $(throw "-rootFolder is required."),
[string]$folders = "bin,obj"
)
Write-Diagnostic "Build: Clean"
Get-ChildItem $rootFolder -Include $folders -Recurse | ForEach-Object {
Remove-Item $_.fullname -Force -Recurse
}
}
function Build-Bootstrap {
param(
[string]$solutionFile = $(throw "-solutionFile is required."),
[string]$nugetExe = $(throw "-nugetExe is required.")
)
Write-Diagnostic "Build: Bootstrap"
$solutionFolder = [System.IO.Path]::GetDirectoryName($solutionFile)
. $nugetExe config -Set Verbosity=quiet
. $nugetExe restore $solutionFile -NonInteractive
Get-ChildItem $solutionFolder -filter packages.config -recurse |
Where-Object { -not ($_.PSIsContainer) } |
ForEach-Object {
. $nugetExe restore $_.FullName -NonInteractive -SolutionDirectory $solutionFolder
}
}
function Build-Nupkg {
param(
[string]$rootFolder = $(throw "-rootFolder is required."),
[string]$project = $(throw "-project is required."),
[string]$nugetExe = $(throw "-nugetExe is required."),
[string]$outputFolder = $(throw "-outputFolder is required."),
[string]$config = $(throw "-config is required."),
[string]$version = $(throw "-version is required."),
[string]$platform = $(throw "-platform is required.")
)
$outputFolder = Join-Path $outputFolder "$config"
$nuspecFilename = [System.IO.Path]::GetFullPath($project) -ireplace ".csproj$", ".nuspec"
if(-not (Test-Path $nuspecFilename)) {
Die("Could not find nuspec: $nuspecFilename")
}
Write-Diagnostic "Creating nuget package for platform $platform"
# http://docs.nuget.org/docs/reference/command-line-reference#Pack_Command
. $nugetExe pack $nuspecFilename -OutputDirectory $outputFolder -Symbols -NonInteractive `
-Properties "Configuration=$config;Bin=$outputFolder;Platform=$platform" -Version $version
if($LASTEXITCODE -ne 0) {
Die("Build failed: $projectName")
}
# Support for multiple build runners
if(Test-Path env:BuildRunner) {
$buildRunner = Get-Content env:BuildRunner
switch -Wildcard ($buildRunner.ToString().ToLower()) {
"myget" {
$mygetBuildFolder = Join-Path $rootFolder "Build"
Create-Folder-Safe -folder $mygetBuildFolder
Get-ChildItem $outputFolder -filter *.nupkg |
Where-Object { -not ($_.PSIsContainer) } |
ForEach-Object {
$fullpath = $_.FullName
$filename = $_.Name
cp $fullpath $mygetBuildFolder\$filename
}
}
}
}
}
function Build-Project {
param(
[string]$project = $(throw "-project is required."),
[string]$outputFolder = $(throw "-outputFolder is required."),
[string]$nugetExe = $(throw "-nugetExe is required."),
[string]$config = $(throw "-config is required."),
[string]$target = $(throw "-target is required."),
[string[]]$targetFrameworks = $(throw "-targetFrameworks is required."),
[string[]]$platform = $(throw "-platform is required.")
)
$projectPath = [System.IO.Path]::GetFullPath($project)
$projectName = [System.IO.Path]::GetFileName($projectPath) -ireplace ".csproj$", ""
Create-Folder-Safe -folder $outputFolder
if(-not (Test-Path $projectPath)) {
Die("Could not find csproj: $projectPath")
}
$targetFrameworks | foreach-object {
$targetFramework = $_
$platformOutputFolder = Join-Path $outputFolder "$config\$targetFramework"
Create-Folder-Safe -folder $platformOutputFolder
Write-Diagnostic "Build: $projectName ($platform / $config - $targetFramework)"
& "$(Get-Content env:windir)\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" `
$projectPath `
/t:$target `
/p:Configuration=$config `
/p:OutputPath=$platformOutputFolder `
/p:TargetFrameworkVersion=$targetFramework `
/p:Platform=$platform `
/m `
/v:M `
/fl `
/flp:LogFile=$platformOutputFolder\msbuild.log `
/nr:false
if($LASTEXITCODE -ne 0) {
Die("Build failed: $projectName ($Config - $targetFramework)")
}
}
}
function Build-Solution {
param(
[string]$rootFolder = $(throw "-rootFolder is required."),
[string]$solutionFile = $(throw "-solutionFile is required."),
[string]$outputFolder = $(throw "-outputFolder is required."),
[string]$version = $(throw "-version is required"),
[string]$config = $(throw "-config is required."),
[string]$target = $(throw "-target is required."),
[bool]$alwaysClean = $(throw "-alwaysclean is required"),
[string[]]$targetFrameworks = $(throw "-targetFrameworks is required."),
[string[]]$projects = $(throw "-projects is required."),
[string[]]$platforms = $(throw "-platforms is required.")
)
if(-not (Test-Path $solutionFile)) {
Die("Could not find solution: $solutionFile")
}
$solutionFolder = [System.IO.Path]::GetDirectoryName($solutionFile)
$nugetExe = if(Test-Path Env:NuGet) { Get-Content env:NuGet } else { Join-Path $solutionFolder ".nuget\nuget.exe" }
if($alwaysClean) {
Build-Clean -root $solutionFolder
}
Build-Bootstrap -solutionFile $solutionFile -nugetExe $nugetExe
$projects | ForEach-Object {
$project = $_
$platforms | ForEach-Object {
$platform = $_
$buildOutputFolder = Join-Path $outputFolder "$version\$platform"
Build-Project -rootFolder $solutionFolder -project $project -outputFolder $buildOutputFolder `
-nugetExe $nugetExe -target $target -config $config `
-targetFrameworks $targetFrameworks -version $version -platform $platform
Build-Nupkg -rootFolder $rootFolder -project $project -nugetExe $nugetExe -outputFolder $buildOutputFolder `
-config $config -version $version -platform $platform
}
}
}
function TestRunner-Nunit {
param(
[string]$outputFolder = $(throw "-outputFolder is required."),
[string]$config = $(throw "-config is required."),
[string]$target = $(throw "-target is required."),
[string[]]$projects = $(throw "-projects is required."),
[string[]]$platforms = $(throw "-platforms is required.")
)
Die("TODO")
}
# Bootstrap
$rootFolder = Split-Path -parent $script:MyInvocation.MyCommand.Definition
$outputFolder = Join-Path $rootFolder "bin"
$testsFolder = Join-Path $outputFolder "tests"
$config = $config.substring(0, 1).toupper() + $config.substring(1)
$version = $config.trim()
# Myget
$currentVersion = if(Test-Path env:PackageVersion) { Get-Content env:PackageVersion } else { $packageVersion }
if($currentVersion -eq "") {
Die("Package version cannot be empty")
}
# Build
$net35projects = @( `
"$rootFolder\src\Flaherty.Services.Net35\Flaherty.Services.Net35.csproj",
"$rootFolder\src\Flaherty.Mapping.BingMaps.Net35\Flaherty.Mapping.BingMaps.Net35.csproj",
"$rootFolder\src\Flaherty.Mapping.BingMaps.WebControls.Net35\Flaherty.Mapping.BingMaps.WebControls.Net35.csproj",
"$rootFolder\src\Flaherty.Mapping.MapQuest.Net35\Flaherty.Mapping.MapQuest.Net35.csproj",
"$rootFolder\src\Flaherty.Mapping.MapQuest.WebControls.Net35\Flaherty.Mapping.MapQuest.WebControls.Net35.csproj"
)
$net35projects | ForEach-Object {
$net35project = $_
$platforms | ForEach-Object {
$platform = $_
$buildOutputFolder = Join-Path $outputFolder "$currentVersion\$platform"
Build-Project -rootFolder $rootFolder `
-project $net35project `
-outputFolder $buildOutputFolder `
-nugetExe $nugetExe `
-target $target `
-config $config `
-targetFrameworks @( "v3.5" ) `
-version $currentVersion `
-platform $platform
}
}
Build-Solution -solutionFile $rootFolder\Flaherty.Mapping.sln `
-projects @( `
"$rootFolder\src\Flaherty.Services\Flaherty.Services.csproj",
"$rootFolder\src\Flaherty.Mapping.BingMaps\Flaherty.Mapping.BingMaps.csproj",
"$rootFolder\src\Flaherty.Mapping.BingMaps.WebControls\Flaherty.Mapping.BingMaps.WebControls.csproj",
"$rootFolder\src\Flaherty.Mapping.MapQuest\Flaherty.Mapping.MapQuest.csproj",
"$rootFolder\src\Flaherty.Mapping.MapQuest.WebControls\Flaherty.Mapping.MapQuest.WebControls.csproj"
) `
-rootFolder $rootFolder `
-outputFolder $outputFolder `
-platforms $platforms `
-version $currentVersion `
-config $config `
-target $target `
-targetFrameworks $targetFrameworks `
-alwaysClean $alwaysClean