Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always look in the 32-bit registry hive for the Windows SDK. #97

Merged
merged 1 commit into from
Nov 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 37 additions & 35 deletions src/msbuild/DNNE.BuildTasks/Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,49 +255,51 @@ public int Compare(Version x, Version y)

private static WinSDK GetLatestWinSDK()
{
using (var kits = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows Kits\Installed Roots"))
{
string win10sdkRoot = (string)kits.GetValue("KitsRoot10");
// Always use the 32-bit hive.
// See https://developercommunity.visualstudio.com/t/ucrt-doesnt-work-in-x64-msbuild/1184283#T-N1201257
using var key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
using var kits = key.OpenSubKey(@"SOFTWARE\Microsoft\Windows Kits\Installed Roots");

// Sort the entries in descending order as
// to defer to the latest version.
var versions = new SortedList<Version, string>(new VersionDescendingOrder());
string win10sdkRoot = (string)kits.GetValue("KitsRoot10");

// Collect the possible SDK versions.
foreach (var verMaybe in kits.GetSubKeyNames())
{
if (!Version.TryParse(verMaybe, out Version versionMaybe))
{
continue;
}
// Sort the entries in descending order as
// to defer to the latest version.
var versions = new SortedList<Version, string>(new VersionDescendingOrder());

versions.Add(versionMaybe, verMaybe);
// Collect the possible SDK versions.
foreach (var verMaybe in kits.GetSubKeyNames())
{
if (!Version.TryParse(verMaybe, out Version versionMaybe))
{
continue;
}

// Find the latest version of the SDK.
foreach (var tgtVerMaybe in versions)
versions.Add(versionMaybe, verMaybe);
}

// Find the latest version of the SDK.
foreach (var tgtVerMaybe in versions)
{
// WinSDK inc and lib paths
var incDir = Path.Combine(win10sdkRoot, "Include", tgtVerMaybe.Value);
var libDir = Path.Combine(win10sdkRoot, "Lib", tgtVerMaybe.Value);
if (!Directory.Exists(incDir) || !Directory.Exists(libDir))
{
// WinSDK inc and lib paths
var incDir = Path.Combine(win10sdkRoot, "Include", tgtVerMaybe.Value);
var libDir = Path.Combine(win10sdkRoot, "Lib", tgtVerMaybe.Value);
if (!Directory.Exists(incDir) || !Directory.Exists(libDir))
{
continue;
}
continue;
}

var sharedIncDir = Path.Combine(incDir, "shared");
var umIncDir = Path.Combine(incDir, "um");
var ucrtIncDir = Path.Combine(incDir, "ucrt");
var umLibDir = Path.Combine(libDir, "um");
var ucrtLibDir = Path.Combine(libDir, "ucrt");
var sharedIncDir = Path.Combine(incDir, "shared");
var umIncDir = Path.Combine(incDir, "um");
var ucrtIncDir = Path.Combine(incDir, "ucrt");
var umLibDir = Path.Combine(libDir, "um");
var ucrtLibDir = Path.Combine(libDir, "ucrt");

return new WinSDK()
{
Version = tgtVerMaybe.Value,
IncPaths = new[] { sharedIncDir, umIncDir, ucrtIncDir },
LibPaths = new[] { umLibDir, ucrtLibDir },
};
}
return new WinSDK()
{
Version = tgtVerMaybe.Value,
IncPaths = new[] { sharedIncDir, umIncDir, ucrtIncDir },
LibPaths = new[] { umLibDir, ucrtLibDir },
};
}

throw new Exception("No Win10 SDK version found.");
Expand Down