-
-
Notifications
You must be signed in to change notification settings - Fork 224
/
build.ps1
303 lines (261 loc) · 7.67 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
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
298
299
300
301
302
303
<#
.SYNOPSIS
Build both x86 and x64 msi
.PARAMETER ConfigBits
Specifies the bitness of the build: 64 or 86, default is 64
.PARAMETER Both
Build both x86 and x64 kits.
.PARAMETER Fast
Build just the .csproj projects using default parameters.
This will build OneMore, OneMorCalendar, OneMoreProtocolHandler, and OneMoreSetupActions.
.PARAMETER Prep
Run DisableOutOfProcBuild. This only needs to be run once on a machine, or after upgrading
or reinstalling Visual Studio. It is required to build installer kits from the command line.
#>
# CmdletBinding adds -Verbose functionality, SupportsShouldProcess adds -WhatIf
[CmdletBinding(SupportsShouldProcess = $true)]
param (
[int] $configbits = 64,
[switch] $fast,
[switch] $both,
[switch] $prep
)
Begin
{
$script:devenv = ''
$script:vsregedit = ''
$script:vdproj = ''
function FindVisualStudio
{
$cmd = Get-Command devenv -ErrorAction:SilentlyContinue
if ($cmd -ne $null)
{
$script:devenv = $cmd.Source
$script:ideroot = Split-Path -Parent $devenv
$script:vsregedit = Join-Path $ideroot 'VSRegEdit.exe'
return $true
}
$0 = 'C:\Program Files\Microsoft Visual Studio\2022'
if (FindVS $0) { return $true }
$0 = 'C:\Program Files (x86)\Microsoft Visual Studio\2019'
return FindVS $0
}
function FindVS
{
param($vsroot)
$script:devenv = Join-Path $vsroot 'Enterprise\Common7\IDE\devenv.com'
if (!(Test-Path $devenv))
{
$script:devenv = Join-Path $vsroot 'Professional\Common7\IDE\devenv.com'
}
if (!(Test-Path $devenv))
{
$script:devenv = Join-Path $vsroot 'Community\Common7\IDE\devenv.com'
}
if (!(Test-Path $devenv))
{
Write-Host "devenv not found in $vsroot" -ForegroundColor Yellow
return $false
}
$script:ideroot = Split-Path -Parent $devenv
$script:vsregedit = Join-Path $ideroot 'VSRegEdit.exe'
return $true
}
function DisableOutOfProcBuild
{
$0 = Join-Path $ideroot 'CommonExtensions\Microsoft\VSI\DisableOutOfProcBuild'
if (Test-Path $0)
{
Push-Location $0
if (Test-Path .\DisableOutOfProcBuild.exe) {
.\DisableOutOfProcBuild.exe
}
Pop-Location
Write-Host '... disabled out-of-proc builds; reboot is recommended'
return
}
Write-Host "*** could not find $0\DisableOutOfProcBuild.exe" -ForegroundColor Yellow
}
function PreserveVdproj
{
Write-Host '... preserving vdproj' -ForegroundColor DarkGray
Copy-Item $vdproj .\vdproj.tmp -Force -Confirm:$false
}
function RestoreVdproj
{
Write-Host '... restoring vdproj' -ForegroundColor DarkGray
Copy-Item .\vdproj.tmp $vdproj -Force -Confirm:$false
Remove-Item .\vdproj.tmp -Force
}
function Configure
{
param([int]$bitness)
$lines = @(Get-Content $vdproj)
$productVersion = $lines | `
Where-Object { $_ -match '"ProductVersion" = "8:(.+?)"' } | `
ForEach-Object { $matches[1] }
Write-Host
Write-Host "... configuring vdproj for x$bitness build of $productVersion" -ForegroundColor Yellow
'' | Out-File $vdproj -nonewline
$lines | ForEach-Object `
{
if ($_ -match '"OutputFileName" = "')
{
# "OutputFilename" = "8:Debug\\OneMore_v_Setupx86.msi"
$line = $_.Replace('OneMore_v_', "OneMore_$($productVersion)_")
if ($bitness -eq 64) {
$line.Replace('x86', 'x64') | Out-File $vdproj -Append
} else {
$line.Replace('x64', 'x86') | Out-File $vdproj -Append
}
}
elseif ($_ -match '"DefaultLocation" = "')
{
# "DefaultLocation" = "8:[ProgramFilesFolder][Manufacturer]\\[ProductName]"
if ($bitness -eq 64) {
$_.Replace('ProgramFilesFolder', 'ProgramFiles64Folder') | Out-File $vdproj -Append
} else {
$_.Replace('ProgramFiles64Folder', 'ProgramFilesFolder') | Out-File $vdproj -Append
}
}
elseif ($_ -match '"TargetPlatform" = "')
{
# x86 -> "3:0"
# x64 -> "3:1"
if ($bitness -eq 64) {
'"TargetPlatform" = "3:1"' | Out-File $vdproj -Append
} else {
'"TargetPlatform" = "3:0"' | Out-File $vdproj -Append
}
}
#elseif ($_ -match '"SourcePath" = .*WebView2Loader\.dll"$')
#{
# if ($bitness -eq 64) {
# $_.Replace('\\x86', '\\x64') | Out-File $vdproj -Append
# $_.Replace('win-x86', 'win-x64') | Out-File $vdproj -Append
# } else {
# $_.Replace('\\x64', '\\x86') | Out-File $vdproj -Append
# $_.Replace('win-x64', 'win-x86') | Out-File $vdproj -Append
# }
#}
elseif (($_ -match '"Name" = "8:OneMoreSetupActions --install ') -or `
($_ -match '"Arguments" = "8:--install '))
{
if ($bitness -eq 64) {
$_.Replace('x86', 'x64') | Out-File $vdproj -Append
} else {
$_.Replace('x64', 'x86') | Out-File $vdproj -Append
}
}
elseif ($_ -notmatch '^"Scc')
{
$_ | Out-File $vdproj -Append
}
}
}
function BuildFast
{
param([int]$bitness)
Write-Host "... building x$bitness DLLs" -ForegroundColor Yellow
# build...
Push-Location OneMore
BuildComponent 'OneMore' $true
Pop-Location
Push-Location OneMoreTray
BuildComponent 'OneMoreTray' $true
Pop-Location
Push-Location OneMoreCalendar
BuildComponent 'OneMoreCalendar' $true
Pop-Location
Push-Location OneMoreProtocolHandler
BuildComponent 'OneMoreProtocolHandler'
Pop-Location
Push-Location OneMoreSetupActions
BuildComponent 'OneMoreSetupActions'
Pop-Location
}
function BuildComponent
{
param($name, $restore = $false)
# output file cannot exist before build
if (Test-Path .\Debug\*)
{
Remove-Item .\Debug\*.* -Force -Confirm:$false
}
# nuget restore
if ($restore)
{
$cmd = 'nuget restore .\$name.csproj'
write-Host $cmd -ForegroundColor DarkGray
nuget restore .\$name.csproj
}
$cmd = "$devenv .\$name.csproj /build ""Debug|AnyCPU"" /project $name /projectconfig Debug"
write-Host $cmd -ForegroundColor DarkGray
. $devenv .\$name.csproj /build "Debug|AnyCPU" /project $name /projectconfig Debug
}
function Build
{
param([int]$bitness)
Write-Host "... building x$bitness MSI" -ForegroundColor Yellow
# output file cannot exist before build
if (Test-Path .\Debug\*)
{
Remove-Item .\Debug\*.* -Force -Confirm:$false
}
if ($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent)
{
Write-Host '... enabling MSBuild verbose logging' -ForegroundColor DarkYellow
$cmd = ". '$vsregedit' set local HKCU General MSBuildLoggerVerbosity dword 4`n"
write-Host $cmd -ForegroundColor DarkGray
. $vsregedit set local HKCU General MSBuildLoggerVerbosity dword 4 | Out-Null
}
$cmd = "$devenv .\OneMoreSetup.vdproj /build ""Debug|x$bitness"" /project Setup /projectconfig Debug /out `$env:TEMP\OneMoreBuild.log"
write-Host $cmd -ForegroundColor DarkGray
# build
. $devenv .\OneMoreSetup.vdproj /build "Debug|x$bitness" /project Setup /projectconfig Debug /out $env:TEMP\OneMorebuild.log
# move msi to Downloads for safe-keeping and to allow next Platform build
Move-Item .\Debug\*.msi $home\Downloads -Force
Write-Host "... x$bitness MSI copied to $home\Downloads\" -ForegroundColor DarkYellow
if ($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent)
{
Write-Host '... disabling MSBuild verbose logging' -ForegroundColor DarkYellow
$cmd = ". '$vsregedit' set local HKCU General MSBuildLoggerVerbosity dword 1`n"
write-Host $cmd -ForegroundColor DarkGray
. $vsregedit set local HKCU General MSBuildLoggerVerbosity dword 1 | Out-Null
}
}
}
Process
{
if (-not (FindVisualStudio))
{
return
}
if ($prep)
{
DisableOutOfProcBuild
return
}
if ($fast)
{
BuildFast 64
}
else
{
Push-Location OneMoreSetup
$script:vdproj = Resolve-Path .\OneMoreSetup.vdproj
PreserveVdproj
if ($configbits -eq 86 -or $both)
{
Configure 86
Build 86
}
if ($configBits -eq 64 -or $both)
{
Configure 64
Build 64
}
RestoreVdproj
}
Pop-Location
}