@@ -18,7 +18,6 @@ public static class WslUtils
18
18
private const string WslUncPrefix = @"\\wsl$\" ;
19
19
private const string WslLocalHostUncPrefix = @"\\wsl.localhost\" ;
20
20
private const string WslCommandName = "wsl.exe" ;
21
- private const string WslInteropEnvar = "WSL_INTEROP" ;
22
21
private const string WslConfFilePath = "/etc/wsl.conf" ;
23
22
private const string DefaultWslMountPrefix = "/mnt" ;
24
23
private const string DefaultWslSysDriveMountName = "c" ;
@@ -61,29 +60,17 @@ private static int GetWslVersion(IEnvironment env, IFileSystem fs)
61
60
return 0 ;
62
61
}
63
62
64
- // The WSL_INTEROP variable is set in WSL2 distributions
65
- if ( env . Variables . TryGetValue ( WslInteropEnvar , out _ ) )
63
+ const string procWslInteropPath = "/proc/sys/fs/binfmt_misc/WSLInterop" ;
64
+ const string procWslInteropLatePath = "/proc/sys/fs/binfmt_misc/WSLInterop-Late" ;
65
+ // The WSLInterop file exists in WSL1 distributions
66
+ if ( fs . FileExists ( procWslInteropPath ) )
66
67
{
67
- return 2 ;
68
+ return 1 ;
68
69
}
69
-
70
- const string procVersionPath = "/proc/version" ;
71
- if ( fs . FileExists ( procVersionPath ) )
70
+ // The WSLInterop-Late file exists in WSL2 distributions
71
+ if ( fs . FileExists ( procWslInteropLatePath ) )
72
72
{
73
- // Both WSL1 and WSL2 distributions include "[Mm]icrosoft" in the version string
74
- string procVersion = fs . ReadAllText ( procVersionPath ) ;
75
- if ( ! Regex . IsMatch ( procVersion , "[Mm]icrosoft" ) )
76
- {
77
- return 0 ;
78
- }
79
-
80
- // WSL2 distributions return "WSL2" in the version string
81
- if ( Regex . IsMatch ( procVersion , "wsl2" , RegexOptions . IgnoreCase ) )
82
- {
83
- return 2 ;
84
- }
85
-
86
- return 1 ;
73
+ return 2 ;
87
74
}
88
75
89
76
return 0 ;
0 commit comments