forked from stevencohn/OneMore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
218 lines (188 loc) · 6.33 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
<#
.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 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] $both,
[switch] $prep
)
Begin
{
$script:devenv = ''
$script:vdproj = ''
function FindVisualStudio
{
$cmd = Get-Command devenv -ErrorAction:SilentlyContinue
if ($cmd -ne $null)
{
$script:devenv = $cmd.Source
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
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 ([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
} else {
$_.Replace('\\x64', '\\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
}
}
else
{
$_ | Out-File $vdproj -Append
}
}
}
function Build ([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
}
$cmd = "$devenv .\OneMoreSetup.vdproj /build ""Debug|x$bitness"" /project Setup /projectconfig Debug"
write-Host $cmd -ForegroundColor DarkGray
# build
. $devenv .\OneMoreSetup.vdproj /build "Debug|x$bitness" /project Setup /projectconfig Debug
# 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
}
}
Process
{
if (-not (FindVisualStudio))
{
return
}
if ($prep)
{
DisableOutOfProcBuild
return
}
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
}