diff --git a/source/Nuke.Common/EnvironmentInfo.Platform.cs b/source/Nuke.Common/EnvironmentInfo.Platform.cs index 753e62c5b..39541b72d 100644 --- a/source/Nuke.Common/EnvironmentInfo.Platform.cs +++ b/source/Nuke.Common/EnvironmentInfo.Platform.cs @@ -3,9 +3,11 @@ // https://github.com/nuke-build/nuke/blob/master/LICENSE using System; +using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Runtime.Versioning; +using Nuke.Common.Utilities; namespace Nuke.Common { @@ -54,6 +56,25 @@ public static bool Is64Bit /// public static bool IsOsx => Platform == PlatformFamily.OSX; + /// + /// Returns whether the operating system is running under Windows Subsystem for Linux. + /// + public static bool IsWsl { get; } = GetIsWsl(); + + private static bool GetIsWsl() { + + if (!IsLinux) + return false; + + try { + var version = File.ReadAllText("/proc/version"); + return version.ContainsOrdinalIgnoreCase("Microsoft"); + } + catch (IOException) { + return false; + } + } + /// /// Returns the framework the build is running on. /// diff --git a/source/Nuke.Common/Tooling/ProcessTasks.cs b/source/Nuke.Common/Tooling/ProcessTasks.cs index 72c97cb04..07e0314f1 100644 --- a/source/Nuke.Common/Tooling/ProcessTasks.cs +++ b/source/Nuke.Common/Tooling/ProcessTasks.cs @@ -89,7 +89,9 @@ private static string GetToolPathOverride(string toolPath) } #if NETCORE - if (EnvironmentInfo.IsUnix && toolPath.EndsWithOrdinalIgnoreCase(".exe")) + if (EnvironmentInfo.IsUnix && + toolPath.EndsWithOrdinalIgnoreCase(".exe") && + !EnvironmentInfo.IsWsl) return ToolPathResolver.GetPathExecutable("mono"); #endif