File tree 1 file changed +17
-1
lines changed
src/BenchmarkDotNet/Portability
1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -185,14 +185,30 @@ public static string GetOsVersion()
185
185
return null ;
186
186
try
187
187
{
188
- return LinuxOsReleaseHelper . GetNameByOsRelease ( File . ReadAllLines ( "/etc/os-release" ) ) ;
188
+ string version = LinuxOsReleaseHelper . GetNameByOsRelease ( File . ReadAllLines ( "/etc/os-release" ) ) ;
189
+ bool wsl = IsUnderWsl ( ) ;
190
+ return wsl ? version + " WSL" : version ;
189
191
}
190
192
catch ( Exception )
191
193
{
192
194
return null ;
193
195
}
194
196
}
195
197
198
+ private static bool IsUnderWsl ( )
199
+ {
200
+ if ( ! IsLinux ( ) )
201
+ return false ;
202
+ try
203
+ {
204
+ return File . Exists ( "/proc/sys/fs/binfmt_misc/WSLInterop" ) ; // https://superuser.com/a/1749811
205
+ }
206
+ catch ( Exception )
207
+ {
208
+ return false ;
209
+ }
210
+ }
211
+
196
212
// TODO: Introduce a common util API for registry calls, use it also in BenchmarkDotNet.Toolchains.CsProj.GetCurrentVersionBasedOnWindowsRegistry
197
213
/// <summary>
198
214
/// On Windows, this method returns UBR (Update Build Revision) based on Registry.
You can’t perform that action at this time.
0 commit comments