From 89e40f1479f9c15deeab8285abb9195c6a849e03 Mon Sep 17 00:00:00 2001 From: Tarek Mahmoud Sayed Date: Thu, 21 Jul 2022 18:51:09 -0700 Subject: [PATCH 1/2] Support using ICU on Windows Server 2019 --- .../TestUtilities/System/PlatformDetection.Windows.cs | 2 ++ src/libraries/System.Globalization/tests/IcuTests.cs | 2 +- .../libs/System.Globalization.Native/pal_icushim.c | 11 +++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.Windows.cs b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.Windows.cs index 6448f7cc42d4b..95c2ae15f044e 100644 --- a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.Windows.cs +++ b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.Windows.cs @@ -24,6 +24,7 @@ public static partial class PlatformDetection public static bool IsWindows8x => IsWindows && GetWindowsVersion() == 6 && (GetWindowsMinorVersion() == 2 || GetWindowsMinorVersion() == 3); public static bool IsWindows8xOrLater => IsWindowsVersionOrLater(6, 2); public static bool IsWindows10OrLater => IsWindowsVersionOrLater(10, 0); + public static bool IsWindowsServer2019 => IsWindows && GetWindowsVersion() == 10 && GetWindowsMinorVersion() == 0 && GetWindowsBuildVersion() == 17763; public static bool IsWindowsNanoServer => IsWindows && (IsNotWindowsIoTCore && GetWindowsInstallationType().Equals("Nano Server", StringComparison.OrdinalIgnoreCase)); public static bool IsWindowsServerCore => IsWindows && GetWindowsInstallationType().Equals("Server Core", StringComparison.OrdinalIgnoreCase); public static int WindowsVersion => IsWindows ? (int)GetWindowsVersion() : -1; @@ -173,6 +174,7 @@ internal static Version GetWindowsVersionObject() internal static uint GetWindowsVersion() => (uint)GetWindowsVersionObject().Major; internal static uint GetWindowsMinorVersion() => (uint)GetWindowsVersionObject().Minor; + internal static uint GetWindowsBuildVersion() => (uint)GetWindowsVersionObject().Build; internal static bool IsWindowsVersionOrLater(int major, int minor, int build = -1) { diff --git a/src/libraries/System.Globalization/tests/IcuTests.cs b/src/libraries/System.Globalization/tests/IcuTests.cs index 671c5036fbd97..0990c710f6d63 100644 --- a/src/libraries/System.Globalization/tests/IcuTests.cs +++ b/src/libraries/System.Globalization/tests/IcuTests.cs @@ -10,7 +10,7 @@ namespace System.Globalization.Tests public class IcuTests { private static bool IsIcuCompatiblePlatform => PlatformDetection.IsNotWindows || - (PlatformDetection.IsWindows10Version1903OrGreater && + ((PlatformDetection.IsWindowsServer2019 || PlatformDetection.IsWindows10Version1903OrGreater) && // Server core doesn't have icu.dll on SysWOW64 !(PlatformDetection.IsWindowsServerCore && PlatformDetection.IsX86Process)); diff --git a/src/native/libs/System.Globalization.Native/pal_icushim.c b/src/native/libs/System.Globalization.Native/pal_icushim.c index 9f8994394e4af..d23499c80b1ee 100644 --- a/src/native/libs/System.Globalization.Native/pal_icushim.c +++ b/src/native/libs/System.Globalization.Native/pal_icushim.c @@ -100,6 +100,17 @@ static int FindICULibs() libicuuc = LoadLibraryExW(L"icu.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); if (libicuuc == NULL) { + // On Windows Server 2019, the ICU library is installed as icuuc.dll and icuin.dll. Try to load these. + libicuuc = LoadLibraryExW(L"icuuc.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); + if (libicuuc != NULL) + { + libicui18n = LoadLibraryExW(L"icuin.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); + if (libicui18n != NULL) + { + return true; + } + } + return false; } From 6790d87d70aafea81a875bc3c003176869e1e737 Mon Sep 17 00:00:00 2001 From: Tarek Mahmoud Sayed Date: Fri, 22 Jul 2022 10:21:29 -0700 Subject: [PATCH 2/2] Exclude Nano Server from Server 2019 checking --- .../tests/TestUtilities/System/PlatformDetection.Windows.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.Windows.cs b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.Windows.cs index 95c2ae15f044e..a06d545cd1c72 100644 --- a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.Windows.cs +++ b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.Windows.cs @@ -24,7 +24,7 @@ public static partial class PlatformDetection public static bool IsWindows8x => IsWindows && GetWindowsVersion() == 6 && (GetWindowsMinorVersion() == 2 || GetWindowsMinorVersion() == 3); public static bool IsWindows8xOrLater => IsWindowsVersionOrLater(6, 2); public static bool IsWindows10OrLater => IsWindowsVersionOrLater(10, 0); - public static bool IsWindowsServer2019 => IsWindows && GetWindowsVersion() == 10 && GetWindowsMinorVersion() == 0 && GetWindowsBuildVersion() == 17763; + public static bool IsWindowsServer2019 => IsWindows && IsNotWindowsNanoServer && GetWindowsVersion() == 10 && GetWindowsMinorVersion() == 0 && GetWindowsBuildVersion() == 17763; public static bool IsWindowsNanoServer => IsWindows && (IsNotWindowsIoTCore && GetWindowsInstallationType().Equals("Nano Server", StringComparison.OrdinalIgnoreCase)); public static bool IsWindowsServerCore => IsWindows && GetWindowsInstallationType().Equals("Server Core", StringComparison.OrdinalIgnoreCase); public static int WindowsVersion => IsWindows ? (int)GetWindowsVersion() : -1;