forked from stevencohn/OneMore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
177 lines (150 loc) · 4.91 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
<#
.SYNOPSIS
Build both x86 and x64 msi
.NOTES
In order for devenv.com to successfully build a vdproj project, the following commands must be
run once on the machine to configure Registry settings:
cd 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\CommonExtensions\Microsoft\VSI\DisableOutOfProcBuild';
.\DisableOutOfProcBuild.exe;
#>
# CmdletBinding adds -Verbose functionality, SupportsShouldProcess adds -WhatIf
[CmdletBinding(SupportsShouldProcess = $true)]
param (
[int] $configbits = 64,
[switch] $both
)
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
}
return $true
}
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
}
}
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
}
# 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
{
Push-Location OneMoreSetup
$script:vdproj = Resolve-Path .\OneMoreSetup.vdproj
if (FindVisualStudio)
{
PreserveVdproj
if ($configbits -eq 86 -or $both)
{
Configure 86
Build 86
}
if ($configBits -eq 64 -or $both)
{
Configure 64
Build 64
}
RestoreVdproj
}
Pop-Location
}