Skip to content

Commit 34208de

Browse files
committed
add Get-WindowsSDK-Path
1 parent df465e7 commit 34208de

File tree

2 files changed

+30
-31
lines changed

2 files changed

+30
-31
lines changed

Build-Unreal-AutoSDK.ps1

+2-31
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ param(
3232

3333
. ".\Get-AutoSDK-PlatformPath.ps1"
3434
. ".\Get-VisualStudio-Installs.ps1"
35+
. ".\Get-WindowsSDK-Path.ps1"
3536

3637
$AutoSDKRoot = Get-Item -Path $Path -ErrorAction SilentlyContinue
3738
if (-not $AutoSDKRoot) {
@@ -116,42 +117,12 @@ $VSInstalls | ForEach-Object {
116117
}
117118
}
118119

119-
$windowsSDKDir = ""
120-
# This method which calls the official Microsoft script to find the Windows SDK works when called from an interactive shell,
121-
# but does not when called from inside a PowerShell script. I do not know why. I would prefer to call the official Microsoft tool,
122-
# so that if the method changes, the script will still work. However, for now, I will use the method contained inside that official
123-
# command, but in PowerShell form.
124-
#$winSDKFinderPath = [IO.Path]::Combine($VSInstalls[0].installationPath, "Common7", "Tools", "vsdevcmd", "core", "vsdevcmd_start.bat")
125-
# Run $winSDKFinderPath and get the environment variable for WIndowsSdkDir
126-
#$windowsSDKDir = (& cmd /c .\GetSDKPath.cmd $winSDKFinderPath)
127-
128-
# TODO: we *could* have the user invoke this script from inside a Visual Studio Developer Command Prompt, in which case we could just use the environment variable.
129-
# I'd rather find out what's wrong with trying to call the official Microsoft script from inside a PowerShell script, though.
130-
131-
# Instead, search HKLM:\SOFTWARE\Wow6432Node, HKCU:\SOFTWARE\Wow6432Node, HKLM:\SOFTWARE, HKCU:\SOFTWARE for the Microsoft\Microsoft SDKs\Windows\v10.0 key
132-
# Epic does not suport Windows 8.1 and lower, so let's just grab for v10. Windows 11 does not have a separate kit at this time.
133-
$keyPath = "\Microsoft\Microsoft SDKs\Windows\v10.0"
134-
$regPathsToSearch = @(
135-
"HKLM:\SOFTWARE"
136-
"HKCU:\SOFTWARE"
137-
"HKLM:\SOFTWARE\Wow6432Node"
138-
"HKCU:\SOFTWARE\Wow6432Node"
139-
)
140-
$regPathsToSearch | ForEach-Object {
141-
$regPath = $_ + $keyPath
142-
Write-Verbose "Searching $regPath"
143-
if (Test-Path $regPath) {
144-
Write-Verbose "Found $regPath"
145-
$windowsSDKDir = (Get-ItemProperty -Path $regPath -Name "InstallationFolder").InstallationFolder
146-
}
147-
}
148-
$windowsSDKDir = Get-Item -Path $windowsSDKDir | Select-Object -ExpandProperty Parent | Select-Object -ExpandProperty FullName
120+
$windowsSDKDir = Get-WindowsSDK-Path
149121
Write-Output "Windows SDK Dir: $windowsSDKDir"
150122

151123
$win10SDKDirPath = [IO.Path]::Combine($windowsSDKDir, "10")
152124
if (-not $SkipWindowsSDK) {
153125
# Copy the Windows SDK to $AutoSDKPlatformPath\Windows Kits\10
154-
# TODO: For reasons I completely don't understand, if I specify "Windows Kits", "10" as the destination, I get "Windows Kits\10\10" as the destination.
155126
$outDir = [IO.Path]::Combine($AutoSDKPlatformPath, "Windows Kits")
156127
if (-not (Test-Path $outDir)) {
157128
Write-Output "Creating directory: $outDir"

Get-WindowsSDK-Path.ps1

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
function Get-WindowsSDK-Path {
2+
# First check the environment for WindowsSdkDir, if it's there, then we're done.
3+
if (-not [string]::IsNullOrEmpty($env:WindowsSdkDir)) {
4+
return $env:WindowsSdkDir
5+
}
6+
# Instead, search HKLM:\SOFTWARE\Wow6432Node, HKCU:\SOFTWARE\Wow6432Node, HKLM:\SOFTWARE, HKCU:\SOFTWARE for the Microsoft\Microsoft SDKs\Windows\v10.0 key
7+
# Epic does not suport Windows 8.1 and lower, so let's just grab for v10. Windows 11 does not have a separate kit at this time.
8+
$keyPath = "\Microsoft\Microsoft SDKs\Windows\v10.0"
9+
$regPathsToSearch = @(
10+
"HKLM:\SOFTWARE"
11+
"HKCU:\SOFTWARE"
12+
"HKLM:\SOFTWARE\Wow6432Node"
13+
"HKCU:\SOFTWARE\Wow6432Node"
14+
)
15+
$windowsSDKDir = $null
16+
$regPathsToSearch | ForEach-Object {
17+
$regPath = $_ + $keyPath
18+
Write-Verbose "Searching $regPath"
19+
if (Test-Path $regPath) {
20+
Write-Verbose "Found $regPath"
21+
$windowsSDKDir = (Get-ItemProperty -Path $regPath -Name "InstallationFolder").InstallationFolder
22+
}
23+
}
24+
if ([string]::IsNullOrEmpty($windowsSDKDir)) {
25+
throw "Could not find Windows SDK installation folder - Install it with the Visual Studio Installer"
26+
}
27+
Get-Item -Path $windowsSDKDir | Select-Object -ExpandProperty Parent | Select-Object -ExpandProperty FullName
28+
}

0 commit comments

Comments
 (0)