Files
WSL/tools/setup-dev-env.ps1
Ben Hillis 91317945d5 Verify WinGet config exists before invoking winget configure (#40496)
* Verify WinGet config exists before invoking winget configure

If the resolved `` does not exist, `winget configure` fails
with a cryptic error rather than telling the user that the config file
is missing. Add an explicit `Test-Path` guard that reports the missing
file path and the expected location, and update the existing failure
message to print the full `` instead of just ``
so it matches the path actually passed to `winget configure`.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Retrigger CI

---------

Co-authored-by: benhillis <17727402+benhillis@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-11 19:54:24 +00:00

92 lines
3.4 KiB
PowerShell

<#
.SYNOPSIS
Sets up the development environment for building WSL.
.DESCRIPTION
Detects any existing Visual Studio 2022 installation and runs the
matching WinGet Configuration to install all prerequisites:
Developer Mode, CMake, Visual Studio 2022, and required workloads
from .vsconfig.
If VS 2022 is already installed, the script picks the configuration
matching that edition (Community, Professional, or Enterprise).
If no VS 2022 is found, it defaults to Community edition.
.EXAMPLE
.\tools\setup-dev-env.ps1
#>
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$repoRoot = (Resolve-Path "$PSScriptRoot\..").Path
$configDir = Join-Path $repoRoot ".config"
# ── Detect existing VS 2022 edition ─────────────────────────────────
$configFile = "configuration.winget" # default: Community
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
if (Test-Path $vswhere)
{
$productId = (& $vswhere -version "[17.0,18.0)" -products * -latest -property productId 2>$null |
Select-Object -First 1)
if ($productId) { $productId = $productId.Trim() }
switch ($productId)
{
"Microsoft.VisualStudio.Product.Professional" {
$configFile = "configuration.vsProfessional.winget"
Write-Host "Detected VS 2022 Professional - using $configFile" -ForegroundColor Green
}
"Microsoft.VisualStudio.Product.Enterprise" {
$configFile = "configuration.vsEnterprise.winget"
Write-Host "Detected VS 2022 Enterprise - using $configFile" -ForegroundColor Green
}
"Microsoft.VisualStudio.Product.Community" {
Write-Host "Detected VS 2022 Community - using $configFile" -ForegroundColor Green
}
default {
Write-Host "No VS 2022 found - will install Community edition" -ForegroundColor Yellow
}
}
}
else
{
Write-Host "No VS 2022 found - will install Community edition" -ForegroundColor Yellow
}
$configPath = Join-Path $configDir $configFile
if (-not (Test-Path -LiteralPath $configPath -PathType Leaf))
{
Write-Host "Configuration file not found: $configPath" -ForegroundColor Red
Write-Host "Ensure the repository is fully checked out and the .config folder contains $configFile." -ForegroundColor Yellow
exit 1
}
# ── Run WinGet Configuration ────────────────────────────────────────
Write-Host ""
Write-Host "Running WinGet Configuration ($configFile)..." -ForegroundColor Cyan
Write-Host " This will install: Developer Mode, CMake, VS 2022 + required components"
Write-Host ""
winget configure --enable
if ($LASTEXITCODE -ne 0)
{
Write-Host "Failed to enable WinGet configuration feature." -ForegroundColor Red
exit 1
}
winget configure -f "$configPath" --accept-configuration-agreements
if ($LASTEXITCODE -ne 0)
{
Write-Host "Failed to apply WinGet configuration file: $configPath" -ForegroundColor Red
exit 1
}
# ── Done ────────────────────────────────────────────────────────────
Write-Host ""
Write-Host "All prerequisites installed. Ready to build!" -ForegroundColor Green
Write-Host ""
Write-Host " cmake ."
Write-Host " cmake --build . -- -m"
Write-Host ""