System.PlatformDetection.GetIsWindowsSubsystemForLinux C# (CSharp) Method

GetIsWindowsSubsystemForLinux() private static method

private static GetIsWindowsSubsystemForLinux ( ) : bool
return bool
        private static bool GetIsWindowsSubsystemForLinux()
        {
            // https://github.com/Microsoft/BashOnWindows/issues/423#issuecomment-221627364

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                const string versionFile = "/proc/version";
                if (File.Exists(versionFile))
                {
                    string s = File.ReadAllText(versionFile);

                    if (s.Contains("Microsoft") || s.Contains("WSL"))
                    {
                        return true;
                    }
                }
            }

            return false;
        }