summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author5an7y <[email protected]>2026-04-02 10:00:58 -0700
committer5an7y <[email protected]>2026-04-02 10:00:58 -0700
commitf9545d33190ad51e13d4bdf2942e83d00fa8e379 (patch)
treede00dfa8477bd51e689228724caf8611a4e7dbb4
parent8508ffaaf97a200fe6e8588333c6ab1383687d4f (diff)
fix: prioritize EWDK over NuGet in auto-detection
The packages\ folder is a passive disk artifact that persists between builds. If someone runs the script from inside an EWDK command prompt while packages\ exists from a previous NuGet restore, Auto mode would incorrectly select NuGet and then fail trying to find a VS installation that may not be present in an EWDK-only setup. EWDK is now checked first because \ being set is an active, explicit signal that the user is intentionally in the EWDK environment. Auto detection order is now: EWDK -> NuGet -> WDK Co-authored-by: Copilot <[email protected]>
-rw-r--r--BuildEnvironment.ps128
1 files changed, 15 insertions, 13 deletions
diff --git a/BuildEnvironment.ps1 b/BuildEnvironment.ps1
index 08f0469e..0b0520da 100644
--- a/BuildEnvironment.ps1
+++ b/BuildEnvironment.ps1
@@ -121,7 +121,9 @@ function Resolve-BuildEnvironment {
.SYNOPSIS
Detects or resolves the active build environment and returns metadata.
.DESCRIPTION
- When RunMode is 'Auto', checks in priority order: NuGet, EWDK, WDK.
+ When RunMode is 'Auto', checks in priority order: EWDK, NuGet, WDK.
+ EWDK is checked first because $env:BuildLab is an active, explicit signal
+ whereas the packages\ folder is a passive disk artifact that may linger.
When RunMode is explicitly set to WDK/NuGet/EWDK, skips detection and uses that mode.
Pass the VsInstallation returned by Initialize-DevShell to avoid prompting the user
a second time when multiple VS installations are present.
@@ -143,18 +145,7 @@ function Resolve-BuildEnvironment {
$effectiveMode = $RunMode
# --- Resolve build environment ---
- if ($effectiveMode -eq 'NuGet' -or
- ($effectiveMode -eq 'Auto' -and (Test-Path "$RepoRoot\packages\*"))) {
- if ($effectiveMode -eq 'NuGet' -and -not (Test-Path "$RepoRoot\packages\*")) {
- Write-Error "RunMode is 'NuGet' but no packages were found under '$RepoRoot\packages\'. Ensure NuGet restore has been run."
- exit 1
- }
- $result.Name = 'NuGet'
- $wdkPackage = Get-ChildItem "$RepoRoot\packages\*WDK.x64*" -Name -ErrorAction SilentlyContinue
- $result.NuGetVersion = ([regex]'(?<=x64\.)(\d+\.){3}\d+').Match($wdkPackage).Value
- $result.BuildNumber = [int]($result.NuGetVersion.Split('.')[2])
- }
- elseif ($effectiveMode -eq 'EWDK' -or
+ if ($effectiveMode -eq 'EWDK' -or
($effectiveMode -eq 'Auto' -and $env:BuildLab -match '^(?<branch>[^.]+)\.(?<build>\d+)\.(?<qfe>[^.]+)$')) {
if ($effectiveMode -eq 'EWDK') {
# Forced EWDK: require BuildLab to be set
@@ -166,6 +157,17 @@ function Resolve-BuildEnvironment {
$result.Name = "EWDK.$($Matches.branch).$($Matches.build).$($Matches.qfe)"
$result.BuildNumber = [int]$Matches.build
}
+ elseif ($effectiveMode -eq 'NuGet' -or
+ ($effectiveMode -eq 'Auto' -and (Test-Path "$RepoRoot\packages\*"))) {
+ if ($effectiveMode -eq 'NuGet' -and -not (Test-Path "$RepoRoot\packages\*")) {
+ Write-Error "RunMode is 'NuGet' but no packages were found under '$RepoRoot\packages\'. Ensure NuGet restore has been run."
+ exit 1
+ }
+ $result.Name = 'NuGet'
+ $wdkPackage = Get-ChildItem "$RepoRoot\packages\*WDK.x64*" -Name -ErrorAction SilentlyContinue
+ $result.NuGetVersion = ([regex]'(?<=x64\.)(\d+\.){3}\d+').Match($wdkPackage).Value
+ $result.BuildNumber = [int]($result.NuGetVersion.Split('.')[2])
+ }
elseif ($effectiveMode -eq 'WDK' -or
($effectiveMode -eq 'Auto' -and $env:UCRTVersion -match '10\.0\.(?<build>\d+)\.0')) {
if ($effectiveMode -eq 'WDK' -and $env:UCRTVersion -notmatch '10\.0\.(?<build>\d+)\.0') {