-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathBuild.ps1
More file actions
151 lines (124 loc) · 6.08 KB
/
Copy pathBuild.ps1
File metadata and controls
151 lines (124 loc) · 6.08 KB
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
#!/usr/bin/env pwsh
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
using module ./build.helpers.psm1
<#
.SYNOPSIS
Build WinGet Studio MSIX packages and bundles.
.DESCRIPTION
This script builds WinGet Studio MSIX packages and bundles for the specified platform(s)
and configuration(s). It can also sign the packages if run with administrator privileges.
.PARAMETER Platform
The platform(s) to build.
Valid values are:
- x64: Build for 64-bit architecture.
- x86: Build for 32-bit architecture.
- arm64: Build for ARM 64-bit architecture.
.PARAMETER Configuration
The configuration(s) to build. Valid values are "Debug" and "Release".
.PARAMETER Version
The version to set for the MSIX packages.
.PARAMETER BuildStep
The build step to execute.
Valid values are:
- all: Build both MSIX packages and bundles.
- msix: Build only MSIX packages.
- msixbundle: Build only MSIX bundles.
.PARAMETER IsRelease
Indicates whether this is a release build. If set, the package will be built as a stable release.
.PARAMETER OutputDir
The output directory for the built packages and bundles. If not specified, defaults to the script's directory.
.PARAMETER Clean
Run dotnet clean before building the solution.
#>
[CmdletBinding()]
param (
[ValidateSet('x64', 'x86', 'arm64')]
[string]$Platform = 'x64',
[ValidateSet('Debug', 'Release')]
[string[]]$Configuration = 'Debug',
[string]$Version,
[ValidateSet('all', 'msix', 'msixbundle')]
[string]$BuildStep = 'all',
[switch]$IsRelease = $false,
[string]$OutputDir,
[switch]$Clean
)
$env:Build_RootDirectory = (Split-Path $MyInvocation.MyCommand.Path)
$env:Build_Platform = $Platform
$env:Build_Configuration = $Configuration
$env:msix_version = Initialize-BuildInfo -Version $Version -IsAzurePipelineBuild ([bool]$env:TF_BUILD)
$msBuildPath = Get-MSBuildPath
if ([string]::IsNullOrEmpty($OutputDir)) {
$OutputDir = $env:Build_RootDirectory
}
if (($BuildStep -ieq 'all') -or ($BuildStep -ieq 'msix')) {
$appxManifestPath = [System.IO.Path]::Combine($env:Build_RootDirectory,
'src',
'WinGetStudio',
'Package.appxmanifest')
$xmlElements = Get-XmlElement -Path $appxManifestPath
$appxmanifest = [System.Xml.Linq.XDocument]::Load($appxManifestPath)
# Cache current (dev) values
$devVersion = $appxManifest.Root.Element($xmlElements.Identity).Attribute('Version').Value
$devPackageName = $appxManifest.Root.Element($xmlElements.Identity).Attribute('Name').Value
$devPackageDisplayName = $appxManifest.Root.Element($xmlElements.Properties).Element($xmlElements.DisplayName).Value
$devAppDisplayNameResource = $appxManifest.Root.Element($xmlElements.Applications).Element($xmlElements.Application).Element($xmlElements.VisualElements).Attribute('DisplayName').Value
# For dev build, use the cached values
$buildRing = 'Dev'
$packageName = $devPackageName
$packageDisplayName = $devPackageDisplayName
$appDisplayNameResource = $devAppDisplayNameResource
# For release build, use the new values
if ($IsRelease) {
$buildRing = 'Stable'
$packageName = 'Microsoft.Windows.WinGetStudio'
$packageDisplayName = 'WinGet Studio (Experimental)'
$appDisplayNameResource = 'ms-resource:AppDisplayNameStable'
}
try {
# Update the appxmanifest
$appxManifest.Root.Element($xmlElements.Identity).Attribute('Version').Value = $env:msix_version
$appxManifest.Root.Element($xmlElements.Identity).Attribute('Name').Value = $packageName
$appxManifest.Root.Element($xmlElements.Properties).Element($xmlElements.DisplayName).Value = $packageDisplayName
$appxManifest.Root.Element($xmlElements.Applications).Element($xmlElements.Application).Element($xmlElements.VisualElements).Attribute('DisplayName').Value = $appDisplayNameResource
$appxManifest.Save($appxmanifestPath)
$solutionPath = [System.IO.Path]::Combine(
$env:Build_RootDirectory,
'src',
'WinGetStudio.sln'
)
Restore-Nuget -SolutionPath $solutionPath -UseInternal:([bool]$env:TF_BUILD)
foreach ($platform in $env:Build_Platform) {
foreach ($configuration in $env:Build_Configuration) {
$appxPackageDir = (Join-Path $OutputDir "AppxPackages\$configuration")
Invoke-MSBuildPackage `
-MsBuildPath $msbuildPath `
-SolutionPath $solutionPath `
-Platform $platform.ToLower() `
-Configuration $configuration.ToLower() `
-OutputDir $appxPackageDir `
-BuildRing $buildRing `
-Clean:$Clean
}
}
}
finally {
# Revert the appxmanifest to dev values
$appxManifest.Root.Element($xmlElements.Identity).Attribute('Version').Value = $devVersion
$appxManifest.Root.Element($xmlElements.Identity).Attribute('Name').Value = $devPackageName
$appxManifest.Root.Element($xmlElements.Properties).Element($xmlElements.DisplayName).Value = $devPackageDisplayName
$appxManifest.Root.Element($xmlElements.Applications).Element($xmlElements.Application).Element($xmlElements.VisualElements).Attribute('DisplayName').Value = $devAppDisplayNameResource
$appxManifest.Save($appxmanifestPath)
}
}
if (($BuildStep -ieq 'all') -or ($BuildStep -ieq 'msixbundle')) {
foreach ($configuration in $env:Build_Configuration) {
$appxPackageDir = (Join-Path $OutputDir "AppxPackages\$configuration")
$appxBundlePath = (Join-Path $OutputDir ("AppxBundles\$configuration\WinGetStudio_" + $env:msix_version + '_8wekyb3d8bbwe.msixbundle'))
New-AppxBundle -InputPath $appxPackageDir -ProjectName WinGetStudio -BundleVersion $env:msix_version -OutputPath $appxBundlePath
if (-not ($env:TF_BUILD) -and (Test-IsAdmin)) {
Invoke-SignPackage -AppxBundlePath $appxBundlePath
}
}
}