mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 03:37:59 +01:00
This pull request refactors and modernizes the PowerToys build scripts to provide a more robust, platform-aware, and user-friendly local build experience. The changes introduce shared PowerShell helpers, add clear documentation, improve Visual Studio environment detection, and unify build logic across scripts. The new approach enables easier builds from any folder, better error reporting, and automatic platform detection for x64/arm64. **Build system modernization and shared helpers:** * Added new shared helper script `build-common.ps1` containing reusable functions for MSBuild invocation, Visual Studio environment initialization, project discovery, and platform auto-detection. This script is now dot-sourced by all build scripts for consistent behavior. * Refactored `build-essentials.ps1` and `build-installer.ps1` to use the shared helpers, enabling automatic Visual Studio dev environment setup and platform detection. Both scripts now work from any folder inside the repo and provide improved logging and error handling. [[1]](diffhunk://#diff-946ed85e16779fdbcfeb7de80f631eae2da0f7bd478e27e22621121b409dde88L1-R73) [[2]](diffhunk://#diff-21888769485d767c43c0895fe315e6f6d7384da62f60ef917d8a61a610da10b9L55-R77) **Improved build workflow and error reporting:** * All build scripts now write detailed logs (full, errors, warnings, binlog) next to the solution/project being built, with troubleshooting guidance documented in the new guidelines. [[1]](diffhunk://#diff-43764921d6c830dbb3a15fe875aebfbc46966ae5ff62f3179adb3ff046b47b9dR1-R284) [[2]](diffhunk://#diff-283bc775aac55085b6a0a47e40b3cf619fff47e20a2f5537fd6dd342d19d2afdR1-R48) * Command-line wrappers (`build.cmd`, `build-essentials.cmd`) added for easy invocation from `cmd.exe`, forwarding all arguments to the PowerShell scripts. [[1]](diffhunk://#diff-4bf353f2a88f1378983e4e2f3a5555e69b6a6ccfbe004001c1ebfe99ca57903dR1-R5) [[2]](diffhunk://#diff-48b3da077cd89d8ed6befe57a781bea813e6f9594bfcefbc320b20dea589c5abR1-R6) **Documentation and usage guidance:** * Introduced `BUILD-GUIDELINES.md` with clear instructions, usage examples, and troubleshooting tips for all build scripts, including platform overrides and log locations. **Installer pipeline improvements:** * The installer build pipeline (`build-installer.ps1`) now uses shared helpers for platform detection and Visual Studio initialization, and passes unified build arguments to all MSBuild invocations, improving consistency and maintainability. [[1]](diffhunk://#diff-21888769485d767c43c0895fe315e6f6d7384da62f60ef917d8a61a610da10b9L83-L126) [[2]](diffhunk://#diff-21888769485d767c43c0895fe315e6f6d7384da62f60ef917d8a61a610da10b9L137-R113) [[3]](diffhunk://#diff-21888769485d767c43c0895fe315e6f6d7384da62f60ef917d8a61a610da10b9L151-R128) [[4]](diffhunk://#diff-21888769485d767c43c0895fe315e6f6d7384da62f60ef917d8a61a610da10b9L162-R142) --- **References:** [[1]](diffhunk://#diff-43764921d6c830dbb3a15fe875aebfbc46966ae5ff62f3179adb3ff046b47b9dR1-R284) [[2]](diffhunk://#diff-946ed85e16779fdbcfeb7de80f631eae2da0f7bd478e27e22621121b409dde88L1-R73) [[3]](diffhunk://#diff-21888769485d767c43c0895fe315e6f6d7384da62f60ef917d8a61a610da10b9L55-R77) [[4]](diffhunk://#diff-283bc775aac55085b6a0a47e40b3cf619fff47e20a2f5537fd6dd342d19d2afdR1-R48) [[5]](diffhunk://#diff-4bf353f2a88f1378983e4e2f3a5555e69b6a6ccfbe004001c1ebfe99ca57903dR1-R5) [[6]](diffhunk://#diff-48b3da077cd89d8ed6befe57a781bea813e6f9594bfcefbc320b20dea589c5abR1-R6) [[7]](diffhunk://#diff-21888769485d767c43c0895fe315e6f6d7384da62f60ef917d8a61a610da10b9L83-L126) [[8]](diffhunk://#diff-21888769485d767c43c0895fe315e6f6d7384da62f60ef917d8a61a610da10b9L137-R113) [[9]](diffhunk://#diff-21888769485d767c43c0895fe315e6f6d7384da62f60ef917d8a61a610da10b9L151-R128) [[10]](diffhunk://#diff-21888769485d767c43c0895fe315e6f6d7384da62f60ef917d8a61a610da10b9L162-R142)
93 lines
3.4 KiB
PowerShell
93 lines
3.4 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Light-weight wrapper to build local projects (solutions/projects) in the current working directory using helpers in build-common.ps1.
|
|
|
|
.DESCRIPTION
|
|
This script is intended for quick local builds. It dot-sources `build-common.ps1` and calls `BuildProjectsInDirectory` against the current directory. Use `-RestoreOnly` to only restore packages for local projects. If `-Platform` is omitted the script attempts to auto-detect the host platform.
|
|
|
|
.PARAMETER Platform
|
|
Target platform (e.g., 'x64', 'arm64'). If omitted the script will try to detect the host platform automatically.
|
|
|
|
.PARAMETER Configuration
|
|
Build configuration (e.g., 'Debug', 'Release'). Default: 'Debug'.
|
|
|
|
.PARAMETER RestoreOnly
|
|
If specified, only perform package restore for local projects and skip the build steps for a solution file (i.e. .sln).
|
|
|
|
.PARAMETER ExtraArgs
|
|
Any remaining, positional arguments passed to the script are forwarded to MSBuild as additional arguments (e.g., '/p:CIBuild=true').
|
|
|
|
.EXAMPLE
|
|
.\tools\build\build.ps1
|
|
Builds any .sln/.csproj/.vcxproj in the current working directory (auto-detects Platform).
|
|
|
|
.EXAMPLE
|
|
.\tools\build\build.ps1 -Platform x64 -Configuration Release
|
|
Builds local projects for x64 Release.
|
|
|
|
.EXAMPLE
|
|
.\tools\build\build.ps1 '/p:CIBuild=true' '/p:SomeOther=Value'
|
|
Pass additional MSBuild arguments; these are forwarded to the underlying msbuild calls.
|
|
|
|
.EXAMPLE
|
|
.\tools\build\build.ps1 -RestoreOnly '/p:CIBuild=true'
|
|
Only restores packages for local projects; ExtraArgs still forwarded to msbuild's restore phase.
|
|
|
|
.NOTES
|
|
- This file expects `build-common.ps1` to be located in the same folder and dot-sources it to load helper functions.
|
|
- ExtraArgs are captured using PowerShell's ValueFromRemainingArguments and joined before being passed to the helpers.
|
|
#>
|
|
|
|
param (
|
|
[string]$Platform = '',
|
|
[string]$Configuration = 'Debug',
|
|
[switch]$RestoreOnly,
|
|
[Parameter(ValueFromRemainingArguments=$true)]
|
|
[string[]]$ExtraArgs
|
|
)
|
|
|
|
. "$PSScriptRoot\build-common.ps1"
|
|
|
|
# Initialize Visual Studio dev environment
|
|
if (-not (Ensure-VsDevEnvironment)) { exit 1 }
|
|
|
|
# If user passed MSBuild-style args (e.g. './build.ps1 /p:CIBuild=true'),
|
|
# those will bind to $Platform/$Configuration; detect those and move them to ExtraArgs.
|
|
$positionalExtra = @()
|
|
if ($Platform -and $Platform -match '^[\/-]') {
|
|
$positionalExtra += $Platform
|
|
$Platform = ''
|
|
}
|
|
if ($Configuration -and $Configuration -match '^[\/-]') {
|
|
$positionalExtra += $Configuration
|
|
$Configuration = 'Debug'
|
|
}
|
|
if ($positionalExtra.Count -gt 0) {
|
|
if (-not $ExtraArgs) { $ExtraArgs = @() }
|
|
$ExtraArgs = $positionalExtra + $ExtraArgs
|
|
}
|
|
|
|
# Auto-detect platform when not provided
|
|
if (-not $Platform -or $Platform -eq '') {
|
|
try {
|
|
$Platform = Get-DefaultPlatform
|
|
Write-Host ("[AUTO-PLATFORM] Detected platform: {0}" -f $Platform)
|
|
} catch {
|
|
Write-Warning "Failed to auto-detect platform; defaulting to x64"
|
|
$Platform = 'x64'
|
|
}
|
|
}
|
|
|
|
$cwd = (Get-Location).ProviderPath
|
|
$extraArgsString = $null
|
|
if ($ExtraArgs -and $ExtraArgs.Count -gt 0) { $extraArgsString = ($ExtraArgs -join ' ') }
|
|
|
|
$built = BuildProjectsInDirectory -DirectoryPath $cwd -ExtraArgs $extraArgsString -Platform $Platform -Configuration $Configuration -RestoreOnly:$RestoreOnly
|
|
if ($built) {
|
|
Write-Host "[BUILD] Local projects built; exiting."
|
|
exit 0
|
|
} else {
|
|
Write-Host "[BUILD] No local projects found in $cwd"
|
|
exit 0
|
|
}
|