Setup-dev-envronment.ps1: Capture prereleases from vswhere (#45813)

<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request

Takes one possible approach to allowing for preview installs to be
detected.

⚠️ This has a possible side effect, in that if folks have installations
side-by-side, this would seem to update the Preview version over the
non-Preview version. That may not be preferable behavior, in which case
we could instead update `$commonPaths` to include it, which would allow
it to be found in the absence of a non-preview release.

If others have a preference I'm happy to adapt, as long as it doesn't
leave Preview users with an error.

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [x] Closes: #45811
<!-- - [ ] Closes: #yyy (add separate lines for additional resolved
issues) -->
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [x] ~~**Tests:** Added/updated and all pass~~ N/A in this case
- [x] ~~**Localization:** All end-user-facing strings can be localized~~
N/A
- [x] ~~**Dev docs:** Added/updated~~ N/A in this case I believe
- [x] ~~**New binaries:** Added on the required places~~ N/A
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

The execution of vsWhere was not returning any items in cases where
prereleases were installed.

This change includes prereleases in the consideration of `-latest`

<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed

 Tested vswhere output directly. Before: no installations. After: 2026
Preview was found

 Tested setup-dev-environment.ps1. Before: warning about missing VS
install. After: operates as expected.
This commit is contained in:
Sean Killeen
2026-03-01 12:44:16 -05:00
committed by GitHub
parent 6c691f59e8
commit 637b58b136

View File

@@ -94,25 +94,30 @@ if (-not $SkipLongPaths) {
try {
$regValue = Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -ErrorAction SilentlyContinue
$longPathsEnabled = ($regValue.LongPathsEnabled -eq 1)
} catch {
}
catch {
$longPathsEnabled = $false
}
if ($longPathsEnabled) {
Write-Host " Long paths already enabled" -ForegroundColor Green
} elseif ($isAdmin) {
}
elseif ($isAdmin) {
Write-Host " Enabling long paths..."
try {
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1 -Type DWord
Write-Host " Long paths enabled" -ForegroundColor Green
} catch {
}
catch {
Write-Warning " Failed to enable long paths: $_"
}
} else {
}
else {
Write-Warning " Long paths not enabled. Run as Administrator to enable, or run manually:"
Write-Host " Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem' -Name 'LongPathsEnabled' -Value 1" -ForegroundColor DarkGray
}
} else {
}
else {
Write-Host "[1/4] Skipping long path check" -ForegroundColor DarkGray
}
@@ -126,13 +131,15 @@ if (-not $SkipDevMode) {
try {
$regValue = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock" -Name "AllowDevelopmentWithoutDevLicense" -ErrorAction SilentlyContinue
$devModeEnabled = ($regValue.AllowDevelopmentWithoutDevLicense -eq 1)
} catch {
}
catch {
$devModeEnabled = $false
}
if ($devModeEnabled) {
Write-Host " Developer Mode already enabled" -ForegroundColor Green
} elseif ($isAdmin) {
}
elseif ($isAdmin) {
Write-Host " Enabling Developer Mode..."
try {
$regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock"
@@ -141,14 +148,17 @@ if (-not $SkipDevMode) {
}
Set-ItemProperty -Path $regPath -Name "AllowDevelopmentWithoutDevLicense" -Value 1 -Type DWord
Write-Host " Developer Mode enabled" -ForegroundColor Green
} catch {
}
catch {
Write-Warning " Failed to enable Developer Mode: $_"
}
} else {
}
else {
Write-Warning " Developer Mode not enabled. Run as Administrator to enable, or enable manually:"
Write-Host " Settings > System > For developers > Developer Mode" -ForegroundColor DarkGray
}
} else {
}
else {
Write-Host "[2/4] Skipping Developer Mode check" -ForegroundColor DarkGray
}
@@ -161,11 +171,12 @@ if (-not $SkipVSComponents) {
$vsConfigPath = Join-Path $repoRoot ".vsconfig"
if (-not (Test-Path $vsConfigPath)) {
Write-Warning " .vsconfig not found at $vsConfigPath"
} else {
}
else {
$vsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
if (-not $VSInstallPath -and (Test-Path $vsWhere)) {
$VSInstallPath = & $vsWhere -latest -property installationPath 2>$null
$VSInstallPath = & $vsWhere -latest -prerelease -property installationPath 2>$null
}
if (-not $VSInstallPath) {
@@ -188,7 +199,8 @@ if (-not $SkipVSComponents) {
if (-not $VSInstallPath -or -not (Test-Path $VSInstallPath)) {
Write-Warning " Could not find Visual Studio installation"
Write-Warning " Please install Visual Studio 2026 (or 2022 17.4+) and try again, or import .vsconfig manually"
} else {
}
else {
Write-Host " Found: $VSInstallPath" -ForegroundColor DarkGray
$vsInstaller = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vs_installer.exe"
@@ -218,35 +230,42 @@ if (-not $SkipVSComponents) {
# Check if VS Installer is already running (it runs as setup.exe from the Installer folder)
$vsInstallerDir = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer"
$vsInstallerRunning = Get-Process -Name "setup" -ErrorAction SilentlyContinue |
Where-Object { $_.Path -and $_.Path.StartsWith($vsInstallerDir, [System.StringComparison]::OrdinalIgnoreCase) }
Where-Object { $_.Path -and $_.Path.StartsWith($vsInstallerDir, [System.StringComparison]::OrdinalIgnoreCase) }
if ($vsInstallerRunning) {
Write-Warning " Visual Studio Installer is already running"
Write-Host " Close it and run this script again, or import .vsconfig manually" -ForegroundColor DarkGray
} else {
}
else {
Write-Host " Launching Visual Studio Installer..."
Write-Host " Close Visual Studio if it's running." -ForegroundColor DarkGray
$process = Start-Process -FilePath $vsInstaller -ArgumentList "modify", "--installPath", "`"$VSInstallPath`"", "--config", "`"$vsConfigPath`"" -Wait -PassThru
if ($process.ExitCode -eq 0) {
Write-Host " VS component installation completed" -ForegroundColor Green
} elseif ($process.ExitCode -eq 3010) {
}
elseif ($process.ExitCode -eq 3010) {
Write-Host " VS component installation completed (restart may be required)" -ForegroundColor Green
} else {
}
else {
Write-Warning " VS Installer exited with code $($process.ExitCode)"
Write-Host " You may need to run the installer manually" -ForegroundColor DarkGray
}
}
} else {
}
else {
Write-Host " Skipped VS component installation"
}
} catch {
}
catch {
Write-Host " Non-interactive mode. Run the command above manually if needed." -ForegroundColor DarkGray
}
} else {
}
else {
Write-Warning " Visual Studio Installer not found"
}
}
}
} else {
}
else {
Write-Host "[3/4] Skipping VS component check" -ForegroundColor DarkGray
}
@@ -263,21 +282,26 @@ if (-not $SkipSubmodules) {
if ($uninitializedCount -eq 0 -and $submoduleStatus) {
Write-Host " Submodules already initialized" -ForegroundColor Green
} else {
}
else {
Write-Host " Running: git submodule update --init --recursive" -ForegroundColor DarkGray
git submodule update --init --recursive
if ($LASTEXITCODE -eq 0) {
Write-Host " Submodules initialized" -ForegroundColor Green
} else {
}
else {
Write-Warning " Submodule initialization may have encountered issues (exit code: $LASTEXITCODE)"
}
}
} catch {
}
catch {
Write-Warning " Failed to initialize submodules: $_"
} finally {
}
finally {
Pop-Location
}
} else {
}
else {
Write-Host "[4/4] Skipping submodule initialization" -ForegroundColor DarkGray
}