This repository has been archived by the owner on Aug 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Build.ps1
280 lines (244 loc) · 12.8 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
Param(
[string]$Platform = "x64",
[string]$Configuration = "debug",
[string]$VersionOfSDK,
[string]$SDKNugetSource,
[string]$Version,
[string]$BuildStep = "all",
[string]$AzureBuildingBranch = "main",
[switch]$IsAzurePipelineBuild = $false,
[switch]$Help = $false
)
$StartTime = Get-Date
if ($Help) {
Write-Host @"
Copyright (c) Microsoft Corporation.
Licensed under the MIT License.
Syntax:
Build.cmd [options]
Description:
Builds Dev Home.
Options:
-Platform <platform>
Only build the selected platform(s)
Example: -Platform x64
Example: -Platform "x86,x64,arm64"
-Configuration <configuration>
Only build the selected configuration(s)
Example: -Configuration Release
Example: -Configuration "Debug,Release"
-Help
Display this usage message.
"@
Exit
}
$env:Build_RootDirectory = (Split-Path $MyInvocation.MyCommand.Path)
$env:Build_Platform = $Platform.ToLower()
$env:Build_Configuration = $Configuration.ToLower()
$env:msix_version = build\Scripts\CreateBuildInfo.ps1 -Version $Version -IsAzurePipelineBuild $IsAzurePipelineBuild
$env:sdk_version = build\Scripts\CreateBuildInfo.ps1 -Version $VersionOfSDK -IsSdkVersion $true -IsAzurePipelineBuild $IsAzurePipelineBuild
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')
if ($IsAzurePipelineBuild) {
Copy-Item (Join-Path $env:Build_RootDirectory "build\nuget.config.internal") -Destination (Join-Path $env:Build_RootDirectory "nuget.config")
}
$ErrorActionPreference = "Stop"
if (($BuildStep -ieq "all") -Or ($BuildStep -ieq "sdk")) {
foreach ($configuration in $env:Build_Configuration.Split(",")) {
extensionsdk\BuildSDKHelper.ps1 -Configuration $configuration -VersionOfSDK $env:sdk_version -IsAzurePipelineBuild $IsAzurePipelineBuild -BypassWarning
}
}
if (($BuildStep -ieq "all") -Or ($BuildStep -ieq "DevSetupAgent") -Or ($BuildStep -ieq "fullMsix")) {
foreach ($configuration in $env:Build_Configuration.Split(",")) {
# We use x86 DevSetupAgent for x64 and x86 Dev Home build. Only need to build it once if we are building multiple platforms.
$builtX86 = $false
foreach ($platform in $env:Build_Platform.Split(",")) {
if ($platform -ieq "arm64") {
HyperVExtension\BuildDevSetupAgentHelper.ps1 -Platform $Platform -Configuration $configuration -VersionOfSDK $env:sdk_version -SDKNugetSource $SDKNugetSource -AzureBuildingBranch $AzureBuildingBranch -IsAzurePipelineBuild $IsAzurePipelineBuild -BypassWarning
}
elseif (-not $builtX86) {
HyperVExtension\BuildDevSetupAgentHelper.ps1 -Platform "x86" -Configuration $configuration -VersionOfSDK $env:sdk_version -SDKNugetSource $SDKNugetSource -AzureBuildingBranch $AzureBuildingBranch -IsAzurePipelineBuild $IsAzurePipelineBuild -BypassWarning
$builtX86 = $true
}
}
}
}
$msbuildPath = &"${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -products * -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe
if ($IsAzurePipelineBuild) {
$nugetPath = "nuget.exe";
} else {
$nugetPath = (Join-Path $env:Build_RootDirectory "build\NugetWrapper.cmd")
}
# Install NuGet Cred Provider
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-Expression "& { $(irm https://aka.ms/install-artifacts-credprovider.ps1) } -AddNetfx"
if (-not([string]::IsNullOrWhiteSpace($SDKNugetSource))) {
& $nugetPath sources add -Source $SDKNugetSource
}
. build\Scripts\CertSignAndInstall.ps1
Try {
if (($BuildStep -ieq "all") -Or ($BuildStep -ieq "msix") -Or ($BuildStep -ieq "fullMsix")) {
$buildRing = "Dev"
$newPackageName = $null
$newPackageDisplayName = $null
$newAppDisplayNameResource = $null
$newWidgetProviderDisplayName = $null
if ($AzureBuildingBranch -ieq "release") {
$buildRing = "Stable"
$newPackageName = "Microsoft.Windows.DevHome"
$newPackageDisplayName = "Dev Home (Preview)"
$newAppDisplayNameResource = "ms-resource:AppDisplayNameStable"
$newWidgetProviderDisplayName = "ms-resource:WidgetProviderDisplayNameStable"
} elseif ($AzureBuildingBranch -ieq "staging") {
$buildRing = "Canary"
$newPackageName = "Microsoft.Windows.DevHome.Canary"
$newPackageDisplayName = "Dev Home (Canary)"
$newAppDisplayNameResource = "ms-resource:AppDisplayNameCanary"
$newWidgetProviderDisplayName = "ms-resource:WidgetProviderDisplayNameCanary"
}
[Reflection.Assembly]::LoadWithPartialName("System.Xml.Linq")
$xIdentity = [System.Xml.Linq.XName]::Get("{http://schemas.microsoft.com/appx/manifest/foundation/windows10}Identity");
$xProperties = [System.Xml.Linq.XName]::Get("{http://schemas.microsoft.com/appx/manifest/foundation/windows10}Properties");
$xDisplayName = [System.Xml.Linq.XName]::Get("{http://schemas.microsoft.com/appx/manifest/foundation/windows10}DisplayName");
$xApplications = [System.Xml.Linq.XName]::Get("{http://schemas.microsoft.com/appx/manifest/foundation/windows10}Applications");
$xApplication = [System.Xml.Linq.XName]::Get("{http://schemas.microsoft.com/appx/manifest/foundation/windows10}Application");
$uapVisualElements = [System.Xml.Linq.XName]::Get("{http://schemas.microsoft.com/appx/manifest/uap/windows10}VisualElements");
$xExtensions = [System.Xml.Linq.XName]::Get("{http://schemas.microsoft.com/appx/manifest/foundation/windows10}Extensions");
$uapExtension = [System.Xml.Linq.XName]::Get("{http://schemas.microsoft.com/appx/manifest/uap/windows10/3}Extension");
$uapAppExtension = [System.Xml.Linq.XName]::Get("{http://schemas.microsoft.com/appx/manifest/uap/windows10/3}AppExtension");
# Update the appxmanifest
$appxmanifestPath = (Join-Path $env:Build_RootDirectory "Packaging\Package.appxmanifest")
$appxmanifest = [System.Xml.Linq.XDocument]::Load($appxmanifestPath)
$appxmanifest.Root.Element($xIdentity).Attribute("Version").Value = $env:msix_version
if (-not ([string]::IsNullOrEmpty($newPackageName))) {
$appxmanifest.Root.Element($xIdentity).Attribute("Name").Value = $newPackageName
}
if (-not ([string]::IsNullOrEmpty($newPackageDisplayName))) {
$appxmanifest.Root.Element($xProperties).Element($xDisplayName).Value = $newPackageDisplayName
}
if (-not ([string]::IsNullOrEmpty($newAppDisplayNameResource))) {
$appxmanifest.Root.Element($xApplications).Element($xApplication).Element($uapVisualElements).Attribute("DisplayName").Value = $newAppDisplayNameResource
$extensions = $appxmanifest.Root.Element($xApplications).Element($xApplication).Element($xExtensions).Elements($uapExtension)
foreach ($extension in $extensions) {
if ($extension.Attribute("Category").Value -eq "windows.appExtension") {
$appExtension = $extension.Element($uapAppExtension)
switch ($appExtension.Attribute("Name").Value) {
"com.microsoft.devhome" {
$appExtension.Attribute("DisplayName").Value = $newAppDisplayNameResource
}
"com.microsoft.windows.widgets" {
$appExtension.Attribute("DisplayName").Value = $newWidgetProviderDisplayName
}
}
}
}
}
$appxmanifest.Save($appxmanifestPath)
# This is needed for vcxproj
& $nugetPath restore
foreach ($platform in $env:Build_Platform.Split(",")) {
foreach ($configuration in $env:Build_Configuration.Split(",")) {
$appxPackageDir = (Join-Path $env:Build_RootDirectory "AppxPackages\$configuration")
Write-Host "Building DevHome for EnvPlatform: $env:Build_Platform Platform: $platform Configuration: $configuration BundlePlatforms: $appxBundlePlatform Dir: $appxPackageDir Ring: $buildRing"
$msbuildArgs = @(
("DevHome.sln"),
("/p:Platform="+$platform),
("/p:Configuration="+$configuration),
("/restore"),
("/binaryLogger:DevHome.$platform.$configuration.binlog"),
("/p:AppxBundle=Never"),
("/p:AppxPackageName=DevHome-$platform"),
("/p:AppxBundlePlatforms="+$platform),
("/p:AppxPackageDir=" + $appxPackageDir),
("/p:AppxPackageTestDir=" + (Join-Path $appxPackageDir "DevHome\")),
("/p:AppxPackageSigningEnabled=false"),
("/p:GenerateAppxPackageOnBuild=true"),
("/p:BuildRing=$buildRing")
)
if (-not([string]::IsNullOrWhiteSpace($VersionOfSDK))) {
$msbuildArgs += ("/p:DevHomeSDKVersion="+$env:sdk_version)
}
if ($BuildStep -ieq "msix") {
$msbuildArgs += ("/p:IgnoreZipPackages=true")
}
& $msbuildPath $msbuildArgs
if (-not($IsAzurePipelineBuild) -And $isAdmin) {
Invoke-SignPackage "$appxPackageDir\DevHome-$platform.msix"
}
}
}
# Reset the appxmanifest to prevent unnecessary code changes
$appxmanifest = [System.Xml.Linq.XDocument]::Load($appxmanifestPath)
$appxmanifest.Root.Element($xIdentity).Attribute("Version").Value = "0.0.0.0"
$appxmanifest.Root.Element($xIdentity).Attribute("Name").Value = "Microsoft.Windows.DevHome.Dev"
$appxmanifest.Root.Element($xProperties).Element($xDisplayName).Value = "Dev Home (Dev)"
$appxmanifest.Root.Element($xApplications).Element($xApplication).Element($uapVisualElements).Attribute("DisplayName").Value = "ms-resource:AppDisplayNameDev"
$extensions = $appxmanifest.Root.Element($xApplications).Element($xApplication).Element($xExtensions).Elements($uapExtension)
foreach ($extension in $extensions) {
if ($extension.Attribute("Category").Value -eq "windows.appExtension") {
$appExtension = $extension.Element($uapAppExtension)
switch ($appExtension.Attribute("Name").Value) {
"com.microsoft.devhome" {
$appExtension.Attribute("DisplayName").Value = "ms-resource:AppDisplayNameDev"
}
"com.microsoft.windows.widgets" {
$appExtension.Attribute("DisplayName").Value = "ms-resource:WidgetProviderDisplayNameDev"
}
}
}
}
$appxmanifest.Save($appxmanifestPath)
}
if (($BuildStep -ieq "stubpackages")) {
[Reflection.Assembly]::LoadWithPartialName("System.Xml.Linq")
$msbuildArgs = @(
("DevHomeStub\DevHomeStub.sln"),
("/p:Configuration=Release"),
("/restore"),
("/p:AppxPackageSigningEnabled=false")
)
# Update the appxmanifest
$xIdentity = [System.Xml.Linq.XName]::Get("{http://schemas.microsoft.com/appx/manifest/foundation/windows10}Identity");
$appxmanifestPath = (Join-Path $env:Build_RootDirectory "DevHomeStub\DevHomeStubPackage\Package.appxmanifest")
$appxmanifest = [System.Xml.Linq.XDocument]::Load($appxmanifestPath)
$versionParts = ($env:msix_version).Split('.')
$versionParts[1] = [string]([int]($versionParts[1]) - 1)
$appxmanifest.Root.Element($xIdentity).Attribute("Version").Value = ($versionParts -join '.')
$appxmanifest.Save($appxmanifestPath)
& $msbuildPath $msbuildArgs
$appxmanifest.Root.Element($xIdentity).Attribute("Version").Value = "0.0.0.0"
$appxmanifest.Save($appxmanifestPath)
}
if (($BuildStep -ieq "all") -Or ($BuildStep -ieq "msixbundle")) {
foreach ($configuration in $env:Build_Configuration.Split(",")) {
.\build\scripts\Create-AppxBundle.ps1 -InputPath (Join-Path $env:Build_RootDirectory "AppxPackages\$configuration\DevHome") -ProjectName DevHome -BundleVersion ([version]$env:msix_version) -OutputPath (Join-Path $env:Build_RootDirectory ("AppxBundles\$configuration\DevHome_" + $env:msix_version + "_8wekyb3d8bbwe.msixbundle"))
if (-not($IsAzurePipelineBuild) -And $isAdmin) {
Invoke-SignPackage ("AppxBundles\$configuration\DevHome_" + $env:msix_version + "_8wekyb3d8bbwe.msixbundle")
}
}
}
} Catch {
$formatString = "`n{0}`n`n{1}`n`n"
$fields = $_, $_.ScriptStackTrace
Write-Host ($formatString -f $fields) -ForegroundColor RED
Exit 1
}
$TotalTime = (Get-Date)-$StartTime
$TotalMinutes = [math]::Floor($TotalTime.TotalMinutes)
$TotalSeconds = [math]::Ceiling($TotalTime.TotalSeconds) - ($totalMinutes * 60)
if (-not($isAdmin)) {
Write-Host @"
WARNING: Cert signing requires admin privileges. To sign, run the following in an elevated Developer Command Prompt.
"@ -ForegroundColor GREEN
foreach ($platform in $env:Build_Platform.Split(",")) {
foreach ($configuration in $env:Build_Configuration.Split(",")) {
$appxPackageFile = (Join-Path $env:Build_RootDirectory ("AppxPackages\$configuration\DevHome\DevHome-$platform.msix"))
Write-Host @"
powershell -command "& { . build\scripts\CertSignAndInstall.ps1; Invoke-SignPackage $appxPackageFile }"
"@ -ForegroundColor GREEN
}
}
}
Write-Host @"
Total Running Time:
$TotalMinutes minutes and $TotalSeconds seconds
"@ -ForegroundColor CYAN