| 1 | <# |
| 2 | .SYNOPSIS |
| 3 | Sets up the development environment for building WSL. |
| 4 | .DESCRIPTION |
| 5 | Detects any existing Visual Studio 2022 installation and runs the |
| 6 | matching WinGet Configuration to install all prerequisites: |
| 7 | Developer Mode, CMake, Visual Studio 2022, and required workloads |
| 8 | from .vsconfig. |
| 9 | |
| 10 | If VS 2022 is already installed, the script picks the configuration |
| 11 | matching that edition (Community, Professional, or Enterprise). |
| 12 | If no VS 2022 is found, it defaults to Community edition. |
| 13 | .EXAMPLE |
| 14 | .\tools\setup-dev-env.ps1 |
| 15 | #> |
| 16 | |
| 17 | Set-StrictMode -Version Latest |
| 18 | $ErrorActionPreference = "Stop" |
| 19 | |
| 20 | $repoRoot = (Resolve-Path "$PSScriptRoot\..").Path |
| 21 | $configDir = Join-Path $repoRoot ".config" |
| 22 | |
| 23 | # ── Detect existing VS 2022 edition ───────────────────────────────── |
| 24 | $configFile = "configuration.winget" # default: Community |
| 25 | $vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" |
| 26 | |
| 27 | if (Test-Path $vswhere) |
| 28 | { |
| 29 | $productId = (& $vswhere -version "[17.0,18.0)" -products * -latest -property productId 2>$null | |
| 30 | Select-Object -First 1) |
| 31 | |
| 32 | if ($productId) { $productId = $productId.Trim() } |
| 33 | |
| 34 | switch ($productId) |
| 35 | { |
| 36 | "Microsoft.VisualStudio.Product.Professional" { |
| 37 | $configFile = "configuration.vsProfessional.winget" |
| 38 | Write-Host "Detected VS 2022 Professional - using $configFile" -ForegroundColor Green |
| 39 | } |
| 40 | "Microsoft.VisualStudio.Product.Enterprise" { |
| 41 | $configFile = "configuration.vsEnterprise.winget" |
| 42 | Write-Host "Detected VS 2022 Enterprise - using $configFile" -ForegroundColor Green |
| 43 | } |
| 44 | "Microsoft.VisualStudio.Product.Community" { |
| 45 | Write-Host "Detected VS 2022 Community - using $configFile" -ForegroundColor Green |
| 46 | } |
| 47 | default { |
| 48 | Write-Host "No VS 2022 found - will install Community edition" -ForegroundColor Yellow |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | else |
| 53 | { |
| 54 | Write-Host "No VS 2022 found - will install Community edition" -ForegroundColor Yellow |
| 55 | } |
| 56 | |
| 57 | $configPath = Join-Path $configDir $configFile |
| 58 | if (-not (Test-Path -LiteralPath $configPath -PathType Leaf)) |
| 59 | { |
| 60 | Write-Host "Configuration file not found: $configPath" -ForegroundColor Red |
| 61 | Write-Host "Ensure the repository is fully checked out and the .config folder contains $configFile." -ForegroundColor Yellow |
| 62 | exit 1 |
| 63 | } |
| 64 | |
| 65 | # ── Run WinGet Configuration ──────────────────────────────────────── |
| 66 | Write-Host "" |
| 67 | Write-Host "Running WinGet Configuration ($configFile)..." -ForegroundColor Cyan |
| 68 | Write-Host " This will install: Developer Mode, CMake, VS 2022 + required components" |
| 69 | Write-Host "" |
| 70 | |
| 71 | winget configure --enable |
| 72 | if ($LASTEXITCODE -ne 0) |
| 73 | { |
| 74 | Write-Host "Failed to enable WinGet configuration feature." -ForegroundColor Red |
| 75 | exit 1 |
| 76 | } |
| 77 | |
| 78 | winget configure -f "$configPath" --accept-configuration-agreements |
| 79 | if ($LASTEXITCODE -ne 0) |
| 80 | { |
| 81 | Write-Host "Failed to apply WinGet configuration file: $configPath" -ForegroundColor Red |
| 82 | exit 1 |
| 83 | } |
| 84 | |
| 85 | # ── Done ──────────────────────────────────────────────────────────── |
| 86 | Write-Host "" |
| 87 | Write-Host "All prerequisites installed. Ready to build!" -ForegroundColor Green |
| 88 | Write-Host "" |
| 89 | Write-Host " cmake ." |
| 90 | Write-Host " cmake --build . -- -m" |
| 91 | Write-Host "" |