Get Windows SDK path from Registry (#19042)

## Summary of the Pull Request
The Windows SDK path may not be the same on all PCs, especially when
Visual Studio (VS) is installed on a drive other than `C:/`. However, we
can read the correct path from the Registry, which this PR does.

## Validation Steps Performed
1. Install VS on `E:/`.
2. Build the solution and see it passes without erroring on accessing
`MakePri.exe`.
This commit is contained in:
Tushar
2026-06-26 01:41:38 +05:30
committed by GitHub
parent d0263b86ac
commit dc4ce1c096
5 changed files with 41 additions and 6 deletions

View File

@@ -22,9 +22,14 @@ Param(
[Parameter(HelpMessage="Path to makeappx.exe")]
[ValidateScript({Test-Path $_ -Type Leaf})]
[string]
$MakeAppxPath = "C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x86\MakeAppx.exe"
$MakeAppxPath
)
If (-not $MakeAppxPath) {
$winSdk10Root = $(Get-ItemPropertyValue -Path "HKLM:\Software\Microsoft\Windows Kits\Installed Roots" -Name "KitsRoot10")
$MakeAppxPath = "$winSdk10Root\bin\10.0.26100.0\x86\MakeAppx.exe"
}
If ($null -Eq (Get-Item $MakeAppxPath -EA:SilentlyContinue)) {
Write-Error "Could not find MakeAppx.exe at `"$MakeAppxPath`".`nMake sure that -MakeAppxPath points to a valid SDK."
Exit 1

View File

@@ -16,11 +16,21 @@ Param(
[Parameter(HelpMessage="Path to makepri.exe")]
[ValidateScript({Test-Path $_ -Type Leaf})]
[string]
$MakePriPath = "C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x64\MakePri.exe"
$MakePriPath
)
$ErrorActionPreference = 'Stop'
If (-not $MakePriPath) {
$winSdk10Root = $(Get-ItemPropertyValue -Path "HKLM:\Software\Microsoft\Windows Kits\Installed Roots" -Name "KitsRoot10")
$MakePriPath = "$winSdk10Root\bin\10.0.26100.0\x64\MakePri.exe"
}
If ($null -Eq (Get-Item $MakePriPath -EA:SilentlyContinue)) {
Write-Error "Could not find MakePriPath.exe at `"$MakePriPath`".`nMake sure that -MakePriPath points to a valid SDK."
Exit 1
}
$tempDir = Join-Path ([System.IO.Path]::GetTempPath()) "tmp$([Convert]::ToString((Get-Random 65535),16).PadLeft(4,'0')).tmp"
New-Item -ItemType Directory -Path $tempDir | Out-Null
$priConfig = Join-Path $tempDir "priconfig.xml"

View File

@@ -17,11 +17,21 @@ Param(
[Parameter(HelpMessage="Path to makepri.exe")]
[ValidateScript({Test-Path $_ -Type Leaf})]
[string]
$MakePriPath = "C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x64\MakePri.exe"
$MakePriPath
)
$ErrorActionPreference = 'Stop'
If (-not $MakePriPath) {
$winSdk10Root = $(Get-ItemPropertyValue -Path "HKLM:\Software\Microsoft\Windows Kits\Installed Roots" -Name "KitsRoot10")
$MakePriPath = "$winSdk10Root\bin\10.0.26100.0\x64\MakePri.exe"
}
If ($null -Eq (Get-Item $MakePriPath -EA:SilentlyContinue)) {
Write-Error "Could not find MakePriPath.exe at `"$MakePriPath`".`nMake sure that -MakePriPath points to a valid SDK."
Exit 1
}
$tempDir = Join-Path ([System.IO.Path]::GetTempPath()) "tmp$([Convert]::ToString((Get-Random 65535),16).PadLeft(4,'0')).tmp"
New-Item -ItemType Directory -Path $tempDir | Out-Null

View File

@@ -25,7 +25,7 @@ Param(
[Parameter(HelpMessage="Path to makeappx.exe", ParameterSetName='Layout')]
[ValidateScript({Test-Path $_ -Type Leaf})]
[string]
$MakeAppxPath = "C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x64\MakeAppx.exe",
$MakeAppxPath,
[Parameter(HelpMessage="Include the portable mode marker file by default", ParameterSetName='AppX')]
[Parameter(HelpMessage="Include the portable mode marker file by default", ParameterSetName='Layout')]
@@ -39,6 +39,11 @@ $filesToCopyFromXaml = @("Microsoft.UI.Xaml.dll", "Microsoft.UI.Xaml") # We don'
$ErrorActionPreference = 'Stop'
If (-not $MakeAppxPath) {
$winSdk10Root = $(Get-ItemPropertyValue -Path "HKLM:\Software\Microsoft\Windows Kits\Installed Roots" -Name "KitsRoot10")
$MakeAppxPath = "$winSdk10Root\bin\10.0.26100.0\x64\MakeAppx.exe"
}
If ($null -Eq (Get-Item $MakeAppxPath -EA:SilentlyContinue)) {
Write-Error "Could not find MakeAppx.exe at `"$MakeAppxPath`".`nMake sure that -MakeAppxPath points to a valid SDK."
Exit 1

View File

@@ -6,13 +6,18 @@ Param(
$Path,
[Parameter(HelpMessage="Path to Windows Kit")]
[ValidateScript({Test-Path $_ -Type Leaf})]
[ValidateScript({Test-Path $_})]
[string]
$WindowsKitPath = "C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0"
$WindowsKitPath
)
$ErrorActionPreference = "Stop"
If (-not $WindowsKitPath) {
$winSdk10Root = $(Get-ItemPropertyValue -Path "HKLM:\Software\Microsoft\Windows Kits\Installed Roots" -Name "KitsRoot10")
$WindowsKitPath = "$winSdk10Root\bin\10.0.26100.0"
}
If ($null -Eq (Get-Item $WindowsKitPath -EA:SilentlyContinue)) {
Write-Error "Could not find a windows SDK at at `"$WindowsKitPath`".`nMake sure that WindowsKitPath points to a valid SDK."
Exit 1