-
-
Notifications
You must be signed in to change notification settings - Fork 679
Expand file tree
/
Copy pathBuild.Modern.ps1
More file actions
193 lines (152 loc) · 8.33 KB
/
Copy pathBuild.Modern.ps1
File metadata and controls
193 lines (152 loc) · 8.33 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
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
<#
.SYNOPSIS
Builds a signed NativeAOT msixbundle from Telegram.Modern.csproj.
.DESCRIPTION
The .NET 10 / CsWinRT / NativeAOT build, packaged by Telegram.Msix.Modern. Installs beside the
shipping app and beside the loose development layout: all three have different identities,
because Windows will not move an installed app between a registered layout and a bundle.
Takes tens of minutes - most of it the ILC link.
Deliberately does not call UpdateManifest.ps1, so the version does not move and each build
replaces the last at the same path. Run it by hand first if you need a bundle that supersedes
an installed one rather than overwriting it.
.EXAMPLE
.\Build.Modern.ps1
.EXAMPLE
.\UpdateManifest.ps1 -path Telegram.Msix -config RELEASE -mode SideloadOnly
.\Build.Modern.ps1 -Identity Original -Instrumented
.EXAMPLE
.\UpdateManifest.ps1 -path Telegram.Msix -config RELEASE -mode StoreUpload
.\Build.Modern.ps1 -Platform ARM64, x64 -Mode StoreUpload -Identity Original
#>
[CmdletBinding()]
param(
# One entry builds a single-architecture bundle; several build one bundle carrying all of them.
# The last is the one MSBuild is invoked for - see the note where AppxBundlePlatforms is passed
# - so put the host architecture last unless you have a reason not to.
#
# A list and a separated string are both accepted, and there is no ValidateSet because of it:
# powershell.exe -File hands every argument over as one string, so -Platform x64,ARM64 arrives
# there as the single value "x64,ARM64" and a set would reject it before the split below.
[string[]] $Platform = 'x64',
[ValidateSet('Release', 'Debug')]
[string] $Configuration = 'Release',
[ValidateSet('SideloadOnly', 'StoreUpload')]
[string] $Mode = 'SideloadOnly',
# Alternative installs beside the shipping bundle. Original carries Telegram.Msix's own
# identity, which is what a beta for testers wants - and which means it replaces the shipping
# app rather than sitting next to it.
[ValidateSet('Alternative', 'Original')]
[string] $Identity = 'Alternative',
# Compiles in the Profiler probes and Instrumentation.Register, which holds a WeakReference per
# registered object for the session. For measuring, never for a bundle anyone else installs.
[switch] $Instrumented
)
$ErrorActionPreference = 'Stop'
$known = 'x64', 'ARM64'
$resolved = [System.Collections.Generic.List[string]]::new()
foreach ($name in ($Platform -split '[,|]')) {
$trimmed = $name.Trim()
if (-not $trimmed) {
continue
}
# Matched rather than used as given, so -Platform arm64 still reaches MSBuild as the name the
# solution and the packaging project spell out.
$canonical = $known | Where-Object { $_ -eq $trimmed } | Select-Object -First 1
if (-not $canonical) {
throw "Unknown platform '$trimmed'. Expected one or more of $($known -join ', ')."
}
if (-not $resolved.Contains($canonical)) {
$resolved.Add($canonical)
}
}
$Platform = $resolved
if ($Mode -eq 'StoreUpload' -and $Identity -ne 'Original') {
Write-Warning "Mode StoreUpload with the $Identity identity: the .msixupload will carry the patched package name and the Store will reject it. Pass -Identity Original for a real submission."
}
# vswhere has to be on PATH, not merely findable: ILC shells out to it while looking for link.exe,
# and without it the AOT step dies with MSB3073 and exit code 123, naming link.exe rather than the
# thing that actually went missing.
$installer = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer'
$vswhere = Join-Path $installer 'vswhere.exe'
if (-not (Test-Path $vswhere)) {
throw "vswhere.exe not found at $vswhere"
}
$env:PATH = "$installer;$env:PATH"
$vs = & $vswhere -latest -prerelease -products * -requires Microsoft.Component.MSBuild -property installationPath
if (-not $vs) {
throw 'No Visual Studio installation with MSBuild was found.'
}
# VS's MSBuild, not the SDK's: modern UWP XAML support is imported from ImportBefore/ImportAfter
# hooks that only VS's copy has.
$msbuild = Join-Path $vs 'MSBuild\Current\Bin\amd64\MSBuild.exe'
if (-not (Test-Path $msbuild)) {
throw "MSBuild.exe not found at $msbuild"
}
# Through the solution, never the project file. $(SolutionDir) is empty otherwise, and the native
# projects then write their .winmd to a path Telegram.Modern.csproj does not read - which fails as
# a stale projection rather than as a missing file.
$solution = Join-Path $PSScriptRoot 'Telegram.Modern.slnx'
# The two native projects still restore through packages.config, which -restore does not cover on
# its own: it drives NuGet's PackageReference restore, and a packages.config project is skipped
# silently. The build then fails on the CppWinRT .props it imports by path, telling you to run a
# restore you just ran. Restoring both kinds costs nothing once the packages are there.
$common = @("-p:Configuration=$Configuration", '-p:RestorePackagesConfig=true',
'-nologo', '-verbosity:minimal', '-m')
# The last platform in AppxBundlePlatforms is the one the packaging targets treat as producing the
# bundle: every other platform is built from it, through the solution and with bundling suppressed,
# and only it runs MakeAppx bundle. Invoking MSBuild for any other one leaves a set of .msix files
# and no bundle at all, so this is the platform the packaging pass is driven with.
$bundlePlatforms = $Platform -join '|'
$producing = $Platform[-1]
# Reaches Telegram.Modern.csproj through the packaging project's ProjectReference, as a global
# property: AdditionalProperties there adds to the set rather than replacing it.
$instrumentation = if ($Instrumented) { @('-p:Instrumented=true') } else { @() }
function Invoke-MSBuild {
param([string[]] $Arguments, [string] $Description)
Write-Host "==> $Description" -ForegroundColor Cyan
& $msbuild @Arguments
if ($LASTEXITCODE -ne 0) {
throw "$Description failed with exit code $LASTEXITCODE."
}
}
# The native components first, for every architecture the bundle will carry. The app consumes their
# .winmd and .dll by path rather than through a ProjectReference, so building the package does not
# build them - and the recursion into the other platforms goes through the solution, which would
# build them there but leaves the driving platform's still missing.
foreach ($p in $Platform) {
Invoke-MSBuild -Description "Telegram.Native, Telegram.Native.Calls ($p)" -Arguments (
@($solution, '-target:Telegram_Native;Telegram_Native_Calls', '-restore', "-p:Platform=$p") + $common)
}
# AppxBundle=Always and AppxBundlePlatforms are what produce a bundle rather than loose .msix files,
# and the Store will not accept switching between the two once an app has shipped as one of them.
Invoke-MSBuild -Description "Telegram.Msix.Modern ($Configuration|$bundlePlatforms, $Identity identity, $Mode)" -Arguments (
@($solution, '-target:Telegram_Msix_Modern', '-restore',
"-p:Platform=$producing",
"-p:ModernPackageBuildMode=$Mode",
"-p:AppxBundlePlatforms=$bundlePlatforms",
'-p:AppxBundle=Always',
'-p:AppxPackageSigningEnabled=True',
"-p:ModernIdentity=$Identity") + $instrumentation + $common)
$packages = Join-Path $PSScriptRoot 'Telegram.Msix.Modern\AppPackages'
function Get-Newest {
param([string] $Extension)
Get-ChildItem $packages -Recurse -Filter "*$Extension" -ErrorAction SilentlyContinue |
Sort-Object LastWriteTime | Select-Object -Last 1
}
# StoreUpload is the legacy name for store-and-sideload: it produces the signed bundle as well, so
# the bundle is the one artifact both modes always have.
$bundle = Get-Newest '.msixbundle'
if (-not $bundle) {
throw "The build reported success but no .msixbundle was found under $packages."
}
Write-Host ''
Write-Host ("{0} ({1:N0} bytes)" -f $bundle.FullName, $bundle.Length) -ForegroundColor Green
if ($Mode -eq 'StoreUpload') {
$upload = Get-Newest '.msixupload'
if (-not $upload) {
throw "The build reported success but no .msixupload was found under $packages."
}
Write-Host ("{0} ({1:N0} bytes)" -f $upload.FullName, $upload.Length) -ForegroundColor Green
Write-Host 'The .msixupload is what Partner Center takes; it is unsigned by design.'
}
Write-Host 'Install with Add-AppDevPackage.ps1 beside the bundle, which also trusts the test certificate.'