File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
src/BenchmarkDotNet/Portability Expand file tree Collapse file tree 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()
185185 return null ;
186186 try
187187 {
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 ;
189191 }
190192 catch ( Exception )
191193 {
192194 return null ;
193195 }
194196 }
195197
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+
196212 // TODO: Introduce a common util API for registry calls, use it also in BenchmarkDotNet.Toolchains.CsProj.GetCurrentVersionBasedOnWindowsRegistry
197213 /// <summary>
198214 /// On Windows, this method returns UBR (Update Build Revision) based on Registry.
You can’t perform that action at this time.
0 commit comments