diff --git a/src/Microsoft.DotNet.Cli.Utils/Command.cs b/src/Microsoft.DotNet.Cli.Utils/Command.cs index 53a00db23..b78918321 100644 --- a/src/Microsoft.DotNet.Cli.Utils/Command.cs +++ b/src/Microsoft.DotNet.Cli.Utils/Command.cs @@ -57,11 +57,18 @@ namespace Microsoft.DotNet.Cli.Utils private static void ResolveExecutablePath(ref string executable, ref string args) { - var fullExecutable = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, executable + Constants.ExeSuffix)); - - if (File.Exists(fullExecutable)) + foreach (string suffix in Constants.RunnableSuffixes) { - executable = fullExecutable; + var fullExecutable = Path.GetFullPath(Path.Combine( + AppContext.BaseDirectory, executable + suffix)); + + if (File.Exists(fullExecutable)) + { + executable = fullExecutable; + + // In priority order we've found the best runnable extension, so break. + break; + } } // On Windows, we want to avoid using "cmd" if possible (it mangles the colors, and a bunch of other things) diff --git a/src/Microsoft.DotNet.Cli.Utils/Constants.cs b/src/Microsoft.DotNet.Cli.Utils/Constants.cs index 2db4a72ab..3ef64fa97 100644 --- a/src/Microsoft.DotNet.Cli.Utils/Constants.cs +++ b/src/Microsoft.DotNet.Cli.Utils/Constants.cs @@ -12,6 +12,12 @@ namespace Microsoft.DotNet.Cli.Utils internal static class Constants { public static readonly string ExeSuffix = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : string.Empty; + + // Priority order of runnable suffixes to look for and run + public static readonly string[] RunnableSuffixes = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) + ? new string[] { ".exe", ".cmd", ".bat" } + : new string[] { string.Empty }; + public static readonly string HostExecutableName = "corehost" + ExeSuffix; public static readonly string DefaultConfiguration = "Debug"; public static readonly string BinDirectoryName = "bin";