Repository navigation
Expand file tree
/
Copy pathBuild-Toolkit-Components.ps1
More file actions
259 lines (193 loc) · 11 KB
/
Copy pathBuild-Toolkit-Components.ps1
File metadata and controls
259 lines (193 loc) · 11 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
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
<#
.SYNOPSIS
Builds toolkit components with specified parameters. Primarily used by maintainers for local testing.
.DESCRIPTION
This script streamlines building and packing Community Toolkit components with the specified parameters. It allows you to specify the MultiTarget TFM(s) to include or exclude, the WinUI major version to use, the components to build, whether to build samples or source, optional packing when provided with a NupkgOutput, and more. The components can be built in Release configuration and individual (per-component) binlogs can be generated by passing -bl.
.PARAMETER MultiTargets
Specifies the MultiTarget TFM(s) to include for building the components. Defaults to 'uwp', 'wasm' and 'wasdk', or to 'all' when -UIFramework is specified.
.PARAMETER ExcludeMultiTargets
Specifies the MultiTarget TFM(s) to exclude for building the components. The default value excludes targets that require additional tooling or workloads to build. Run uno-check to install the required workloads.
.PARAMETER DateForVersion
Specifies the date for versioning in 'YYMMDD' format. The default value is the current date.
.PARAMETER PreviewVersion
Specifies the preview version to use if packaging is enabled. Appended with a dash after the version number (formatted Version-PreviewVersion). This parameter is optional.
.PARAMETER NupkgOutput
Specifies the output directory for .nupkg files. This parameter is optional. When supplied, the components will also be packed and nupkg files will be output to the specified directory.
.PARAMETER BinlogOutput
Specifies the output directory for binlogs. This parameter is optional, default is the current directory.
.PARAMETER EnableBinLogs
Enables the generation of binlogs by appending '/bl' to the msbuild command. Generated binlogs will match the csproj name. This parameter is optional. Use BinlogOutput to specify the output directory.
.PARAMETER WinUIMajorVersion
Specifies the WinUI major version to use. WinUI 2 is only supported by 'uwp', while WinUI 3 is supported by 'wasdk' and all Uno targets, and WinUI 0 selects non-WinUI components ('netstandard'). If not specified, WinUI 2 is used when only 'uwp' is requested, otherwise WinUI 3. Prefer -UIFramework when packing, as WinUI 3 spans both the WinUI and Uno packages.
.PARAMETER UIFramework
Specifies the UI framework to build the components for, which decides the package id (CommunityToolkit.Uwp.*, CommunityToolkit.WinUI.* or CommunityToolkit.Uno.*): 'uwp' (WinUI 2), 'winui' (WinUI 3 with the Windows App SDK), 'uno' (all the Uno targets) or 'none' (non-WinUI components). The requested MultiTargets are narrowed to the ones of that framework, and the WinUI major version is implied. Each UI framework has its own set of packages, so packing (-NupkgOutput) requires the MultiTargets of exactly one of them: pack each framework in a separate run.
.PARAMETER Components
Specifies the names of the components to build. Defaults to all components.
.PARAMETER ExcludeComponents
Specifies the names of the components to exclude from building. This parameter is optional.
.PARAMETER ComponentDir
Specifies the directories to build. Defaults to 'src'. Use 'samples' to build the sample projects instead of the source projects.
.PARAMETER AdditionalProperties
Additional msbuild properties to pass.
.PARAMETER Release
Specifies whether to build in Release configuration. When specified, it adds /p:Configuration=Release to the msbuild arguments.
.PARAMETER Verbose
Specifies whether to enable detailed msbuild verbosity. When specified, it adds /v:detailed to the msbuild arguments.
.EXAMPLE
Build-Toolkit-Components -MultiTargets 'uwp' -DateForVersion '220101' -PreviewVersion 'local' -NupkgOutput 'C:\Output' -BinlogOutput 'C:\Logs' -EnableBinLogs -Components 'MyComponent1', 'MyComponent2' -ExcludeComponents 'MyComponent3' -Release -Verbose
Builds the 'MyComponent1' and 'MyComponent2' components for the 'uwp' target framework with version '220101' and preview version 'local'. The 'MyComponent3' component will be excluded from building. The .nupkg files will be copied to 'C:\Output' and binlogs will be generated in 'C:\Logs'. The components will be built in Release configuration with detailed msbuild verbosity.
.EXAMPLE
foreach ($ui in 'uwp', 'winui', 'uno', 'none') { Build-Toolkit-Components -UIFramework $ui -NupkgOutput 'C:\Output' -Release }
Packs every component once per UI framework: the Uwp, WinUI and Uno packages each only contain the target frameworks of their framework ('none' is for components that only target netstandard).
.NOTES
Author: Arlo Godfrey
Date: 2/19/2024
#>
Param (
[ValidateSet('all', 'wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')]
[Alias("mt")]
[string[]]$MultiTargets = @('uwp', 'wasm', 'wasdk'), # default settings
[ValidateSet('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')]
[string[]]$ExcludeMultiTargets = @(), # default settings
[Alias("c")]
[string[]]$Components = @("all"),
[string[]]$ExcludeComponents = @(),
[string]$DateForVersion = (Get-Date -UFormat %y%m%d),
[string]$PreviewVersion,
[string]$NupkgOutput,
[Alias("bl")]
[switch]$EnableBinLogs,
[Alias("blo")]
[string]$BinlogOutput,
[Alias("p")]
[hashtable]$AdditionalProperties,
[Alias("winui")]
[Nullable[int]]$WinUIMajorVersion = $null,
[ValidateSet('none', 'uwp', 'winui', 'uno')]
[Alias("ui")]
[string]$UIFramework,
[string]$ComponentDir = "src",
[switch]$Release,
[Alias("v")]
[switch]$Verbose
)
if ($UIFramework -and -not $PSBoundParameters.ContainsKey('MultiTargets')) {
$MultiTargets = @('all')
}
if ($MultiTargets -eq 'all') {
$MultiTargets = @('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')
}
if ($null -eq $ExcludeMultiTargets)
{
$ExcludeMultiTargets = @()
}
# WinUI 2 is only supported by uwp, and WinUI 3 by wasdk and Uno. Both uwp and wasdk share a targetframework, so they cannot be enabled at once.
$resolveArgs = @{ MultiTargets = $MultiTargets; ExcludeMultiTargets = $ExcludeMultiTargets; WinUIMajorVersion = $WinUIMajorVersion }
if ($UIFramework) {
$resolveArgs.UIFramework = $UIFramework
}
$resolved = & $PSScriptRoot\MultiTarget\Resolve-MultiTargets.ps1 @resolveArgs
$MultiTargets = $resolved.MultiTargets
$WinUIMajorVersion = $resolved.WinUIMajorVersion
# Each UI framework has its own set of packages, which can't contain the target frameworks of another one.
if ($NupkgOutput -and $resolved.UIFrameworks.Count -gt 1) {
throw "Cannot pack the MultiTargets '$MultiTargets' together, as they belong to more than one UI framework ($($resolved.UIFrameworks -join ', ')), which each have their own packages. Pack one UI framework at a time, with -UIFramework uwp|winui|uno."
}
Write-Output "Building components '$Components' for MultiTargets: $MultiTargets"
if ($ExcludeComponents) {
$Components = $Components | Where-Object { $_ -notin $ExcludeComponents }
}
& $PSScriptRoot\MultiTarget\UseTargetFrameworks.ps1 -MultiTargets $MultiTargets -ExcludeMultiTargets $ExcludeMultiTargets
function Invoke-MSBuildWithBinlog {
param (
[string]$TargetHeadPath
)
# Reset build args to default
$msbuildArgs = @("/p:DebugType=Portable")
# Add "-r" parameter if not running on linux
if ($($PSVersionTable.Platform) -ne "Unix") {
$msbuildArgs += "-r"
}
# Otherwise, add "-restore" parameter
else {
$msbuildArgs += "-restore"
}
# Add "-m" parameter if not running on linux
if ($($PSVersionTable.Platform) -ne "Unix") {
$msbuildArgs += "-m"
}
# Add packing to the msbuild arguments if NupkgOutput is supplied
if ($NupkgOutput) {
# Ensure output is relative to $pwd, not to the csproj of each component.
$NupkgOutput = (Resolve-Path $NupkgOutput).Path
$msbuildArgs += "-t:Build,Pack"
$msbuildArgs += "/p:PackageOutputPath=$NupkgOutput"
$msbuildArgs += "/p:DateForVersion=$DateForVersion"
$msbuildArgs += "/p:PreviewVersion=$PreviewVersion"
}
else {
$msbuildArgs += "-t:Build"
}
# Add additional properties to the msbuild arguments
if ($AdditionalProperties) {
foreach ($property in $AdditionalProperties.GetEnumerator()) {
$msbuildArgs += "/p:$($property.Name)=$($property.Value)"
}
}
# Handle binlog options
if ($EnableBinLogs) {
$csprojFileName = [System.IO.Path]::GetFileNameWithoutExtension($TargetHeadPath)
$defaultBinlogFilename = "$csprojFileName.msbuild.binlog"
$finalBinlogPath = $defaultBinlogFilename;
# Set default binlog output location if not provided
if ($BinlogOutput) {
$finalBinlogPath = "$BinlogOutput/$defaultBinlogFilename"
}
# Add binlog output path to the msbuild arguments
$msbuildArgs += "/bl:$finalBinlogPath"
}
if ($Release) {
$msbuildArgs += "/p:Configuration=Release"
}
if ($Verbose) {
$msbuildArgs += "/v:detailed"
}
# If platform is linux, use dotnet instead of msbuild
if ($($PSVersionTable.Platform) -eq "Unix") {
dotnet build $msbuildArgs $TargetHeadPath
}
else {
msbuild $msbuildArgs $TargetHeadPath
}
}
if ($Components -eq @('all')) {
$Components = @('**')
}
# Components are built individually
foreach ($ComponentName in $Components) {
# Find all components source csproj (when wildcard), or find specific component csproj by name.
foreach ($componentCsproj in Get-ChildItem -Path "$PSScriptRoot/../components/$ComponentName/$ComponentDir/*.csproj") {
# Get component name from csproj path
$componentPath = Get-Item "$componentCsproj/../../"
$componentName = $($componentPath.BaseName);
if ($componentName -in $ExcludeComponents) {
continue;
}
# Get supported MultiTarget for this component
$supportedMultiTargets = & $PSScriptRoot\MultiTarget\Get-MultiTargets.ps1 -component $componentName
$shouldBuild = & $PSScriptRoot\MultiTarget\Test-Component-Support.ps1 `
-RequestedMultiTargets $MultiTargets `
-SupportedMultiTargets $supportedMultiTargets `
-Component $componentName `
-WinUIMajorVersion $WinUIMajorVersion
if (-not $shouldBuild.IsSupported) {
Write-Warning "Skipping $componentName. $($shouldBuild.Reason)"
continue
}
# Filter ExcludeMultiTargets out of supportedMultiTargets
# For display purposes only. The actual build uses the EnabledMultiTargets.props + EnabledTargetFrameworks.props to calculate supported targets at build time.
$supportedMultiTargets = $supportedMultiTargets | Where-Object { $_ -in $MultiTargets }
Write-Output "Building $componentName for MultiTargets '$supportedMultiTargets'"
Invoke-MSBuildWithBinlog $componentCsproj.FullName $EnableBinLogs $BinlogOutput
}
}