Browse Source

Fix StartupTests.StartsWithDotnetInstallLocation (#6589)

Justin Kotalik 7 years ago
parent
commit
3f4622ffe0

+ 13 - 4
src/Servers/IIS/AspNetCoreModuleV2/CommonLib/HostFxrResolver.cpp

@@ -259,13 +259,22 @@ HostFxrResolver::GetAbsolutePathToDotnet(
     }
 
     auto isWow64Process = Environment::IsRunning64BitProcess();
-    const auto platform = isWow64Process? L"x64" : L"x86";
+
+    std::wstring regKeySubSection;
+
+    if (isWow64Process)
+    {
+        regKeySubSection = L"SOFTWARE\\WOW6432Node\\dotnet\\Setup\\InstalledVersions\\x64\\sdk";
+    }
+    else
+    {
+        regKeySubSection = L"SOFTWARE\\dotnet\\Setup\\InstalledVersions\\x86\\sdk";
+    }
 
     const auto installationLocation = RegistryKey::TryGetString(
         HKEY_LOCAL_MACHINE,
-        std::wstring(L"SOFTWARE\\dotnet\\Setup\\InstalledVersions\\") + platform + L"\\sdk",
-        L"InstallLocation",
-        RRF_SUBKEY_WOW6432KEY);
+        regKeySubSection,
+        L"InstallLocation");
 
     if (installationLocation.has_value())
     {

+ 3 - 3
src/Servers/IIS/AspNetCoreModuleV2/CommonLib/RegistryKey.cpp

@@ -16,11 +16,11 @@ std::optional<DWORD> RegistryKey::TryGetDWORD(HKEY section, const std::wstring&
     return dwData;
 }
 
-std::optional<std::wstring> RegistryKey::TryGetString(HKEY section, const std::wstring& subSectionName, const std::wstring& valueName, DWORD flags)
+std::optional<std::wstring> RegistryKey::TryGetString(HKEY section, const std::wstring& subSectionName, const std::wstring& valueName)
 {
     DWORD cbData;
 
-    if (!CheckReturnValue(RegGetValue(section, subSectionName.c_str(), valueName.c_str(), RRF_RT_REG_SZ | flags, nullptr, nullptr, &cbData) != NO_ERROR))
+    if (!CheckReturnValue(RegGetValue(section, subSectionName.c_str(), valueName.c_str(), RRF_RT_REG_SZ, nullptr, nullptr, &cbData)))
     {
         return std::nullopt;
     }
@@ -28,7 +28,7 @@ std::optional<std::wstring> RegistryKey::TryGetString(HKEY section, const std::w
     std::wstring data;
     data.resize(cbData / sizeof(wchar_t));
 
-    if (!CheckReturnValue(RegGetValue(section, subSectionName.c_str(), valueName.c_str(), RRF_RT_REG_SZ | flags, nullptr, data.data(), &cbData) != NO_ERROR))
+    if (!CheckReturnValue(RegGetValue(section, subSectionName.c_str(), valueName.c_str(), RRF_RT_REG_SZ, nullptr, data.data(), &cbData)))
     {
         return std::nullopt;
     }

+ 1 - 1
src/Servers/IIS/AspNetCoreModuleV2/CommonLib/RegistryKey.h

@@ -13,7 +13,7 @@ public:
     std::optional<DWORD> TryGetDWORD(HKEY section, const std::wstring& subSectionName, const std::wstring& valueName, DWORD flags = 0);
 
     static
-    std::optional<std::wstring> TryGetString(HKEY section, const std::wstring& subSectionName, const std::wstring& valueName, DWORD flags = 0);
+    std::optional<std::wstring> TryGetString(HKEY section, const std::wstring& subSectionName, const std::wstring& valueName);
 
 private:
     static