-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy path_PostBuild.ps1
277 lines (233 loc) · 9.16 KB
/
_PostBuild.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
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
param (
[string] $projectName,
[string] $configurationName,
[string] $targetName,
[string] $platformName
)
function Usage
{
Write-Host 'usage: _PostBuild.ps1 -projectName <project name> -configurationName <configuration name> [-targetName <targetName>] [-platformName <platformName>]'
Write-Host 'The targetName parameter is not optional for plugins or projects with translation files'
Write-Host 'The platformName parameter is not optional for BaseStationImport'
Exit 1
}
if([string]::IsNullOrWhiteSpace($projectName) -or [string]::IsNullOrWhiteSpace($configurationName)) {
Usage
}
$pathFromSolution = '';
if($projectName.ToLowerInvariant() -eq 'basestationimport') {
$pathFromSolution = 'Utilities'
}
$solutionDir = Split-Path -Parent $PSCommandPath
$projectDir = [io.Path]::Combine($solutionDir, $pathFromSolution, $projectName)
$virtualRadarDirX86 = [io.Path]::Combine($solutionDir, 'VirtualRadar', 'bin', 'x86', $configurationName)
$virtualRadarDirX64 = [io.Path]::Combine($solutionDir, 'VirtualRadar', 'bin', 'x64', $configurationName)
$virtualRadarDir = switch($platformName) {
'x64' { $virtualRadarDirX64 }
'x86' { $virtualRadarDirX86 }
default { '::UNDEFINED-' + $platformName + '::' }
}
Write-Host ('**********')
Write-Host ('Running post-build steps for project ' + $projectName + ' (' + $configurationName + ' configuration, ' + $platformName + ' platform)')
Write-Host ('Solution folder: ' + $solutionDir)
Write-Host ('Project folder: ' + $projectDir)
Write-Host ('VirtualRadar build folder (x86): ' + $virtualRadarDirX86)
Write-Host ('VirtualRadar build folder (x64): ' + $virtualRadarDirX64)
Write-Host ('VirtualRadar build folder: ' + $virtualRadarDir)
Write-Host ('**********')
function Copy-File
{
param (
[string] $source,
[string] $destFolder,
[switch] $ignoreIfMissing
)
Write-Host ('Copying ' + $source + ' to ' + $destFolder)
if(![io.File]::Exists($source)) {
if(!$ignoreIfMissing) {
Write-Host ($source + ' does not exist')
Write-Host 'Cannot copy missing file'
Exit 1
}
} else {
if(![io.Directory]::Exists($destFolder)) {
Write-Host ('Creating folder ' + $destFolder)
$dirInfo = [io.Directory]::CreateDirectory($destFolder)
}
Copy-Item $source $destFolder
}
}
function Delete-Folder
{
param (
[string] $folder
)
if([io.Directory]::Exists($folder)) {
Write-Host ('Deleting folder ' + $folder)
Remove-Item $folder -Recurse -Force
$retryCounter = 0
while([io.Directory]::Exists($folder)) {
if($retryCounter -gt 3) {
Write-Host 'Could not remove folder'
Exit 1
}
++$retryCounter
Start-Sleep -Milliseconds 500
}
}
}
function Copy-Folder
{
param (
[string] $sourceFolder,
[string] $destFolder,
[switch] $deleteBeforeCopy,
[switch] $recursive
)
if($deleteBeforeCopy) {
Delete-Folder $destFolder
}
Write-Host ("Copying " + $sourceFolder + " to " + $destFolder)
if(!$recursive) {
Copy-Item $sourceFolder $destFolder
} else {
Copy-Item $sourceFolder $destFolder -Recurse
}
}
function Checksum-Folder
{
param (
[string] $folder,
[string] $checksumFile
)
Write-Host ('Generating checksums for ' + $folder)
Write-Host ('Saving checksums to ' + $checksumFile)
$checksumScript = [IO.Path]::Combine($solutionDir, '_ChecksumFiles.ps1')
& $checksumScript -root "$folder" -out "$checksumFile" -addContentChecksum
if($LASTEXITCODE -ne 0) {
Write-Host ([String]::Format('The checksum script failed with an exit code of {0}', $LASTEXITCODE))
Exit 1
}
}
function Copy-PluginWebFolder
{
param (
[string] $projectWebDir,
[string] $destWebDir
)
if(![string]::IsNullOrWhiteSpace($projectWebDir)) {
$webDir = [io.Path]::Combine($projectDir, $projectWebDir)
if([io.Directory]::Exists($webDir)) {
$pluginWebDir = [io.Path]::Combine($pluginDir, $destWebDir);
Copy-Folder $webDir $pluginWebDir -recursive
}
}
}
function Copy-Translations
{
param (
[string] $buildFolder
)
if([string]::IsNullOrWhiteSpace($targetName)) {
Usage
}
Get-ChildItem $buildFolder -Directory |
Where-Object {
$_.Name -match '[a-z]{2}\-[A-Z]{2}'
} |
ForEach-Object {
$sourceDll = [io.Path]::Combine($_.FullName, ($targetName + ".resources.dll"))
# Note that the file might not exist if no translations have been done for the plugin but
# the plugin refers to a library that *does* have translations. The reference will create
# the language folders but there won't be any resource DLLs for the plugin in them.
$targetDir = [io.Path]::Combine($virtualRadarDirX86, $_.Name)
Copy-File $sourceDll $targetDir -ignoreIfMissing
$targetDir = [io.Path]::Combine($virtualRadarDirX64, $_.Name)
Copy-File $sourceDll $targetDir -ignoreIfMissing
}
}
function PostBuild-WebSite-Project
{
$siteDir = [io.Path]::Combine($projectDir, 'Site')
$webDir = [io.Path]::Combine($siteDir, 'Web')
# Checksum the web folder
# The unit tests on the web site need to have the checksums file in a fixed location, i.e.
# its folder should not include the configuration name
$checksumOut = [io.Path]::Combine($virtualRadarDirX86, 'Checksums.txt')
Checksum-Folder -folder $webDir -checksumFile $checksumOut
Copy-File $checksumOut $siteDir
$checksumOut = [io.Path]::Combine($virtualRadarDirX64, 'Checksums.txt')
Checksum-Folder -folder $webDir -checksumFile $checksumOut
Copy-File $checksumOut $siteDir
# Copy the web folder to the VRS build folder
$vrsWebDir = [io.Path]::Combine($virtualRadarDirX86, "Web")
Copy-Folder $webDir $vrsWebDir -deleteBeforeCopy -recursive
$vrsWebDir = [io.Path]::Combine($virtualRadarDirX64, "Web")
Copy-Folder $webDir $vrsWebDir -deleteBeforeCopy -recursive
}
function PostBuild-Plugin
{
param (
[string] $pluginName = '',
[string] $projectWebDir = 'Web',
[string] $destWebDir = 'Web',
[string] $projectWebAdminDir = 'Web-WebAdmin',
[string] $destWebAdminDir = 'Web-WebAdmin'
)
if([string]::IsNullOrWhiteSpace($targetName)) {
Usage
}
if([string]::IsNullOrWhiteSpace($pluginName)) {
$lastDotIdx = $projectName.LastIndexOf('.')
if($lastDotIdx -eq -1) {
Write-Host ("Cannot extract name of plugin from " + $projectName + ", use -pluginName parameter")
Exit 1
}
$pluginName = $projectName.Substring($lastDotIdx + 1)
}
foreach ($vrsBuildDir in $virtualRadarDirX86, $virtualRadarDirX64) {
$pluginsRoot = [io.Path]::Combine($vrsBuildDir, "Plugins")
$pluginDir = [io.Path]::Combine($pluginsRoot, $pluginName)
$pluginBuildDir = [io.Path]::Combine($projectDir, "bin", $configurationName)
$pluginDll = [io.Path]::Combine($pluginBuildDir, ($targetName + '.dll'))
$pluginManifest = [io.Path]::Combine($pluginBuildDir, ($targetName + '.xml'))
Delete-Folder $pluginDir
Copy-File $pluginDll $pluginDir
Copy-File $pluginManifest $pluginDir
Copy-PluginWebFolder $projectWebDir $destWebDir
Copy-PluginWebFolder $projectWebAdminDir $destWebAdminDir
Copy-Translations -buildFolder $pluginBuildDir
}
}
function PostBuild-VirtualRadar-Service
{
if([string]::IsNullOrWhiteSpace($targetName)) {
Usage
}
$buildFolder = [io.Path]::Combine($projectDir, "bin", $platformName, $configurationName)
Copy-File ([io.Path]::Combine($buildFolder, ($targetName + '.exe'))) $virtualRadarDir
Copy-File ([io.Path]::Combine($buildFolder, ($targetName + '.exe.config'))) $virtualRadarDir
}
function PostBuild-BaseStationImport
{
if([string]::IsNullOrWhiteSpace($targetName)) {
Usage
}
$buildFolder = [io.Path]::Combine($projectDir, "bin", $platformName, $configurationName)
Copy-File ([io.Path]::Combine($buildFolder, ($targetName + '.exe'))) $virtualRadarDir
Copy-File ([io.Path]::Combine($buildFolder, ($targetName + '.exe.config'))) $virtualRadarDir
Copy-File ([io.Path]::Combine($buildFolder, ($targetName + '.pdb'))) $virtualRadarDir
}
# Main switch
$caselessProject = $projectName.ToLowerInvariant()
if($caselessProject -eq 'virtualradar.website') {
PostBuild-WebSite-Project
} elseif($caselessProject.StartsWith('plugin.')) {
PostBuild-Plugin
} elseif($caselessProject -eq 'virtualradar-service') {
PostBuild-VirtualRadar-Service
} elseif($caselessProject -eq 'basestationimport') {
PostBuild-BaseStationImport
} else {
Write-Host ('Need to add code for ' + $projectName + ' to the _PostBuild.ps1 script')
}