|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | + Builds toolkit components with specified parameters. Primarily used by maintainers for local testing. |
| 4 | +
|
| 5 | +.DESCRIPTION |
| 6 | + 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. |
| 7 | +
|
| 8 | +.PARAMETER MultiTargets |
| 9 | + Specifies the MultiTarget TFM(s) to include for building the components. The default value is 'all'. |
| 10 | +
|
| 11 | +.PARAMETER ExcludeMultiTargets |
| 12 | + 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. |
| 13 | +
|
| 14 | +.PARAMETER DateForVersion |
| 15 | + Specifies the date for versioning in 'YYMMDD' format. The default value is the current date. |
| 16 | +
|
| 17 | +.PARAMETER PreviewVersion |
| 18 | + Specifies the preview version to use if packaging is enabled. Appended with a dash after the version number (formatted Version-PreviewVersion). This parameter is required when NupkgOutput is supplied. |
| 19 | +
|
| 20 | +.PARAMETER NupkgOutput |
| 21 | + 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. |
| 22 | +
|
| 23 | +.PARAMETER BinlogOutput |
| 24 | + Specifies the output directory for binlogs. This parameter is optional, default is the current directory. |
| 25 | +
|
| 26 | +.PARAMETER EnableBinLogs |
| 27 | + 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. |
| 28 | +
|
| 29 | +.PARAMETER WinUIMajorVersion |
| 30 | + Specifies the WinUI major version to use when building for Uno. Also decides the package id and dependency variant. The default value is '2'. |
| 31 | +
|
| 32 | +.PARAMETER Components |
| 33 | + Specifies the names of the components to build. Defaults to all components. |
| 34 | +
|
| 35 | +.PARAMETER ExcludeComponents |
| 36 | + Specifies the names of the components to exclude from building. This parameter is optional. |
| 37 | +
|
| 38 | +.PARAMETER ComponentDir |
| 39 | + Specifies the directories to build. Defaults to 'src'. Use 'samples' to build the sample projects instead of the source projects. |
| 40 | +
|
| 41 | +.PARAMETER AdditionalProperties |
| 42 | + Additional msbuild properties to pass. |
| 43 | +
|
| 44 | +.PARAMETER Release |
| 45 | + Specifies whether to build in Release configuration. When specified, it adds /p:Configuration=Release to the msbuild arguments. |
| 46 | +
|
| 47 | +.PARAMETER Verbose |
| 48 | + Specifies whether to enable detailed msbuild verbosity. When specified, it adds /v:detailed to the msbuild arguments. |
| 49 | +
|
| 50 | +.EXAMPLE |
| 51 | + Build-Toolkit-Components -MultiTargets 'uwp', 'wasm' -DateForVersion '220101' -PreviewVersion 'local' -NupkgOutput 'C:\Output' -BinlogOutput 'C:\Logs' -EnableBinLogs -Components 'MyComponent1', 'MyComponent2' -ExcludeComponents 'MyComponent3' -Release -Verbose |
| 52 | +
|
| 53 | + Builds the 'MyComponent1' and 'MyComponent2' components for the 'uwp' and 'wasm' target frameworks 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. |
| 54 | +
|
| 55 | +.NOTES |
| 56 | + Author: Arlo Godfrey |
| 57 | + Date: 2/19/2024 |
| 58 | +#> |
| 59 | +Param ( |
| 60 | + [ValidateSet('all', 'wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')] |
| 61 | + [string[]]$MultiTargets = @('all'), |
| 62 | + |
| 63 | + [ValidateSet('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')] |
| 64 | + [string[]]$ExcludeMultiTargets = @('wpf', 'linuxgtk', 'macos', 'ios', 'android'), |
| 65 | + |
| 66 | + [string[]]$Components = @("all"), |
| 67 | + |
| 68 | + [string[]]$ExcludeComponents, |
| 69 | + |
| 70 | + [string]$DateForVersion = (Get-Date -UFormat %y%m%d), |
| 71 | + |
| 72 | + [string]$PreviewVersion, |
| 73 | + |
| 74 | + [string]$NupkgOutput, |
| 75 | + |
| 76 | + [Alias("bl")] |
| 77 | + [switch]$EnableBinLogs, |
| 78 | + |
| 79 | + [string]$BinlogOutput, |
| 80 | + |
| 81 | + [hashtable]$AdditionalProperties, |
| 82 | + |
| 83 | + [int]$WinUIMajorVersion = 2, |
| 84 | + |
| 85 | + [string]$ComponentDir = "src", |
| 86 | + |
| 87 | + [switch]$Release, |
| 88 | + |
| 89 | + [Alias("v")] |
| 90 | + [switch]$Verbose |
| 91 | +) |
| 92 | + |
| 93 | +if ($MultiTargets -eq 'all') { |
| 94 | + $MultiTargets = @('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard') |
| 95 | +} |
| 96 | + |
| 97 | +if ($null -eq $ExcludeMultiTargets) |
| 98 | +{ |
| 99 | + $ExcludeMultiTargets = @() |
| 100 | +} |
| 101 | + |
| 102 | +$MultiTargets = $MultiTargets | Where-Object { $_ -notin $ExcludeMultiTargets } |
| 103 | + |
| 104 | +if ($Components -eq @('all')) { |
| 105 | + $Components = @('**') |
| 106 | +} |
| 107 | + |
| 108 | +if ($ExcludeComponents) { |
| 109 | + $Components = $Components | Where-Object { $_ -notin $ExcludeComponents } |
| 110 | +} |
| 111 | + |
| 112 | +# Check if NupkgOutput is supplied without PreviewVersion |
| 113 | +if ($NupkgOutput -and -not $PreviewVersion) { |
| 114 | + throw "PreviewVersion is required when NupkgOutput is supplied." |
| 115 | +} |
| 116 | + |
| 117 | +# Use the specified MultiTarget TFM and WinUI version |
| 118 | +& $PSScriptRoot\MultiTarget\UseTargetFrameworks.ps1 $MultiTargets |
| 119 | +& $PSScriptRoot\MultiTarget\UseUnoWinUI.ps1 $WinUIMajorVersion |
| 120 | + |
| 121 | +function Invoke-MSBuildWithBinlog { |
| 122 | + param ( |
| 123 | + [string]$TargetHeadPath |
| 124 | + ) |
| 125 | + |
| 126 | + # Reset build args to default |
| 127 | + $msbuildArgs = @("-r", "-m", "/p:DebugType=Portable") |
| 128 | + |
| 129 | + # Add packing to the msbuild arguments if NupkgOutput is supplied |
| 130 | + if ($NupkgOutput) { |
| 131 | + # Ensure output is relative to $pwd, not to the csproj of each component. |
| 132 | + $NupkgOutput = (Resolve-Path $NupkgOutput).Path |
| 133 | + |
| 134 | + $msbuildArgs += "-t:Clean,Build,Pack" |
| 135 | + $msbuildArgs += "/p:PackageOutputPath=$NupkgOutput" |
| 136 | + $msbuildArgs += "/p:DateForVersion=$DateForVersion" |
| 137 | + $msbuildArgs += "/p:PreviewVersion=$PreviewVersion" |
| 138 | + } |
| 139 | + else { |
| 140 | + $msbuildArgs += "-t:Clean,Build" |
| 141 | + } |
| 142 | + |
| 143 | + # Add additional properties to the msbuild arguments |
| 144 | + if ($AdditionalProperties) { |
| 145 | + foreach ($property in $AdditionalProperties.GetEnumerator()) { |
| 146 | + $msbuildArgs += "/p:$($property.Name)=$($property.Value)" |
| 147 | + } |
| 148 | + } |
| 149 | + |
| 150 | + # Handle binlog options |
| 151 | + if ($EnableBinLogs) { |
| 152 | + $csprojFileName = [System.IO.Path]::GetFileNameWithoutExtension($TargetHeadPath) |
| 153 | + $defaultBinlogFilename = "$csprojFileName.msbuild.binlog" |
| 154 | + $finalBinlogPath = $defaultBinlogFilename; |
| 155 | + |
| 156 | + # Set default binlog output location if not provided |
| 157 | + if ($BinlogOutput) { |
| 158 | + $finalBinlogPath = "$BinlogOutput/$defaultBinlogFilename" |
| 159 | + } |
| 160 | + |
| 161 | + # Add binlog output path to the msbuild arguments |
| 162 | + $msbuildArgs += "/bl:$finalBinlogPath" |
| 163 | + } |
| 164 | + |
| 165 | + if ($Release) { |
| 166 | + $msbuildArgs += "/p:Configuration=Release" |
| 167 | + } |
| 168 | + |
| 169 | + if ($Verbose) { |
| 170 | + $msbuildArgs += "/v:detailed" |
| 171 | + } |
| 172 | + |
| 173 | + msbuild $msbuildArgs $TargetHeadPath |
| 174 | +} |
| 175 | + |
| 176 | +# Components are built individually |
| 177 | +foreach ($ComponentName in $Components) { |
| 178 | + # Find all components source csproj (when wildcard), or find specific component csproj by name. |
| 179 | + foreach ($componentCsproj in Get-ChildItem -Path "$PSScriptRoot/../components/$ComponentName/$ComponentDir/*.csproj") { |
| 180 | + # Get component name from csproj path |
| 181 | + $componentPath = Get-Item "$componentCsproj/../../" |
| 182 | + |
| 183 | + # Get supported MultiTarget for this component |
| 184 | + $supportedMultiTargets = & $PSScriptRoot\MultiTarget\Get-MultiTargets.ps1 -component $($componentPath.BaseName) |
| 185 | + |
| 186 | + # Flag to check if any of the requested targets are supported by the component |
| 187 | + $isTargetSupported = $false |
| 188 | + |
| 189 | + foreach ($requestedTarget in $MultiTargets) { |
| 190 | + if ($requestedTarget -in $supportedMultiTargets) { |
| 191 | + $isTargetSupported = $true |
| 192 | + break |
| 193 | + } |
| 194 | + } |
| 195 | + |
| 196 | + # If none of the requested targets are supported by the component, we can skip build to save time and avoid errors. |
| 197 | + if (-not $isTargetSupported) { |
| 198 | + Write-Warning "Skipping $($componentPath.BaseName), none of the requested MultiTargets are enabled for this component." |
| 199 | + continue |
| 200 | + } |
| 201 | + |
| 202 | + Invoke-MSBuildWithBinlog $componentCsproj.FullName $EnableBinLogs $BinlogOutput |
| 203 | + } |
| 204 | +} |
0 commit comments