Skip to content

Commit 1798ba9

Browse files
authored
Merge pull request #254 from CommunityToolkit/fix/packaging/winui-race-condition
Skip building components that don't target the requested WinUI version
2 parents ecad04d + fe08caf commit 1798ba9

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

Build-Toolkit-Components.ps1

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
Param (
6060
[ValidateSet('all', 'wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')]
6161
[Alias("mt")]
62-
[string[]]$MultiTargets = @('uwp', 'wasdk', 'wasm'), # default settings
62+
[string[]]$MultiTargets = @('uwp', 'wasm'), # default settings
6363

6464
[ValidateSet('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')]
6565
[string[]]$ExcludeMultiTargets = @(), # default settings
@@ -207,6 +207,12 @@ function Invoke-MSBuildWithBinlog {
207207
}
208208
}
209209

210+
# List of WinUI-2 compatible multitargets
211+
$WinUI2MultiTargets = @('uwp', 'wasm', 'wpf', 'linuxgtk', 'macos', 'ios', 'android')
212+
213+
# List of WinUI-3 compatible multitargets
214+
$WinUI3MultiTargets = @('wasdk', 'wasm', 'wpf', 'linuxgtk', 'macos', 'ios', 'android')
215+
210216
# Components are built individually
211217
foreach ($ComponentName in $Components) {
212218
# Find all components source csproj (when wildcard), or find specific component csproj by name.
@@ -215,26 +221,45 @@ foreach ($ComponentName in $Components) {
215221
$componentPath = Get-Item "$componentCsproj/../../"
216222
$componentName = $($componentPath.BaseName);
217223

218-
if ($componenName -in $ExcludeComponents) {
224+
if ($componentName -in $ExcludeComponents) {
219225
continue;
220226
}
221227

222228
# Get supported MultiTarget for this component
223229
$supportedMultiTargets = & $PSScriptRoot\MultiTarget\Get-MultiTargets.ps1 -component $componentName
224-
230+
231+
# If the component does not support at least one target that supports the requested WinUI major version, skip the component
232+
$isWinUIMajorVersionSupported = $false
233+
225234
# Flag to check if any of the requested targets are supported by the component
226-
$isTargetSupported = $false
235+
$isRequestedTargetSupported = $false
227236

228237
foreach ($requestedTarget in $MultiTargets) {
229-
if ($requestedTarget -in $supportedMultiTargets) {
230-
$isTargetSupported = $true
231-
break
238+
if ($false -eq $isRequestedTargetSupported) {
239+
$isRequestedTargetSupported = $requestedTarget -in $supportedMultiTargets
240+
}
241+
}
242+
243+
foreach ($supportedMultiTarget in $supportedMultiTargets) {
244+
if ($false -eq $isWinUIMajorVersionSupported) {
245+
if ($WinUIMajorVersion -eq 2) {
246+
$isWinUIMajorVersionSupported = $supportedMultiTarget -in $WinUI2MultiTargets;
247+
}
248+
249+
if ($WinUIMajorVersion -eq 3) {
250+
$isWinUIMajorVersionSupported = $supportedMultiTarget -in $WinUI3MultiTargets;
251+
}
232252
}
233253
}
234254

235255
# If none of the requested targets are supported by the component, we can skip build to save time and avoid errors.
236-
if (-not $isTargetSupported) {
237-
Write-Warning "Skipping $($componentPath.BaseName), none of the requested MultiTargets are enabled for this component."
256+
if (-not $isRequestedTargetSupported) {
257+
Write-Warning "Skipping $($componentPath.BaseName), none of the requested MultiTargets '$MultiTargets' are enabled for this component."
258+
continue
259+
}
260+
261+
if (-not $isWinUIMajorVersionSupported) {
262+
Write-Warning "Skipping $($componentPath.BaseName), none of the supported MultiTargets '$supportedMultiTargets' support WinUI $WinUIMajorVersion."
238263
continue
239264
}
240265

0 commit comments

Comments
 (0)