diff --git a/src/Framework/NativeMethods.cs b/src/Framework/NativeMethods.cs index 3cd7934c726..63888fd973b 100644 --- a/src/Framework/NativeMethods.cs +++ b/src/Framework/NativeMethods.cs @@ -594,25 +594,70 @@ private static void SetMaxPath() } } - internal static bool IsMaxPathLegacyWindows() + internal enum LongPathsStatus + { + /// + /// The registry key is set to 0 or does not exist. + /// + Disabled, + + /// + /// The registry key does not exist. + /// + Missing, + + /// + /// The registry key is set to 1. + /// + Enabled, + + /// + /// Not on Windows. + /// + NotApplicable, + } + + internal static LongPathsStatus IsLongPathsEnabled() { + if (!IsWindows) + { + return LongPathsStatus.NotApplicable; + } + try { - return IsWindows && !IsLongPathsEnabledRegistry(); + return IsLongPathsEnabledRegistry(); } catch { - return true; + return LongPathsStatus.Disabled; } } + internal static bool IsMaxPathLegacyWindows() + { + var longPathsStatus = IsLongPathsEnabled(); + return longPathsStatus == LongPathsStatus.Disabled || longPathsStatus == LongPathsStatus.Missing; + } + [SupportedOSPlatform("windows")] - private static bool IsLongPathsEnabledRegistry() + private static LongPathsStatus IsLongPathsEnabledRegistry() { using (RegistryKey fileSystemKey = Registry.LocalMachine.OpenSubKey(WINDOWS_FILE_SYSTEM_REGISTRY_KEY)) { - object longPathsEnabledValue = fileSystemKey?.GetValue(WINDOWS_LONG_PATHS_ENABLED_VALUE_NAME, 0); - return fileSystemKey != null && Convert.ToInt32(longPathsEnabledValue) == 1; + object longPathsEnabledValue = fileSystemKey?.GetValue(WINDOWS_LONG_PATHS_ENABLED_VALUE_NAME, -1); + if (fileSystemKey != null && Convert.ToInt32(longPathsEnabledValue) == -1) + { + return LongPathsStatus.Missing; + } + else if (fileSystemKey != null && Convert.ToInt32(longPathsEnabledValue) == 1) + { + return LongPathsStatus.Enabled; + } + else + { + return LongPathsStatus.Disabled; + } } } diff --git a/src/MSBuild/Resources/Strings.resx b/src/MSBuild/Resources/Strings.resx index 1129806b5c5..5dba823befb 100644 --- a/src/MSBuild/Resources/Strings.resx +++ b/src/MSBuild/Resources/Strings.resx @@ -1661,6 +1661,19 @@ succeeded: {0} {0} whole number + + Based on the Windows registry key LongPathsEnabled, the LongPaths feature is {0}. + "Windows" is the OS, "LongPathsEnabled" should not be localized, and {0} will be "enabled"/"disabled"/"not set" + + + enabled + + + disabled + + + not set +