diff --git a/src/Cli/Microsoft.DotNet.Cli.Utils/ForwardingAppImplementation.cs b/src/Cli/Microsoft.DotNet.Cli.Utils/ForwardingAppImplementation.cs index 64cafb93850d..0e67e5cf95b7 100644 --- a/src/Cli/Microsoft.DotNet.Cli.Utils/ForwardingAppImplementation.cs +++ b/src/Cli/Microsoft.DotNet.Cli.Utils/ForwardingAppImplementation.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +#if NET + using System.Collections.Generic; using System.Diagnostics; using Microsoft.DotNet.Cli.Utils; @@ -13,8 +15,6 @@ namespace Microsoft.DotNet.Cli.Utils /// internal class ForwardingAppImplementation { - private const string HostExe = "dotnet"; - private readonly string _forwardApplicationPath; private readonly IEnumerable _argsToForward; private readonly string _depsFile; @@ -97,7 +97,10 @@ public ForwardingAppImplementation WithEnvironmentVariable(string name, string v private string GetHostExeName() { - return $"{HostExe}{FileNameSuffixes.CurrentPlatform.Exe}"; + // Should instead make this a full path to dotnet + return System.Environment.ProcessPath; } } } + +#endif \ No newline at end of file diff --git a/src/Cli/dotnet/CommandFactory/CommandResolution/WindowsExePreferredCommandSpecFactory.cs b/src/Cli/dotnet/CommandFactory/CommandResolution/WindowsExePreferredCommandSpecFactory.cs index a2a793dc3fef..df6fc0176ea6 100644 --- a/src/Cli/dotnet/CommandFactory/CommandResolution/WindowsExePreferredCommandSpecFactory.cs +++ b/src/Cli/dotnet/CommandFactory/CommandResolution/WindowsExePreferredCommandSpecFactory.cs @@ -50,7 +50,7 @@ private CommandSpec CreateCommandSpecWrappedWithCmd( string command, IEnumerable args) { - var comSpec = Environment.GetEnvironmentVariable("ComSpec") ?? "cmd.exe"; + var comSpec = Environment.GetEnvironmentVariable("ComSpec") ?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "cmd.exe"); // Handle the case where ComSpec is already the command if (command.Equals(comSpec, StringComparison.OrdinalIgnoreCase)) diff --git a/src/Cli/dotnet/Telemetry/MacAddressGetter.cs b/src/Cli/dotnet/Telemetry/MacAddressGetter.cs index c02c20ce4395..9b1b1a0edc20 100644 --- a/src/Cli/dotnet/Telemetry/MacAddressGetter.cs +++ b/src/Cli/dotnet/Telemetry/MacAddressGetter.cs @@ -10,6 +10,7 @@ using System.Net.NetworkInformation; using System.ComponentModel; using Microsoft.DotNet.Cli.Utils; +using System.IO; namespace Microsoft.DotNet.Cli.Telemetry { @@ -64,9 +65,14 @@ private static string ParseMACAddress(string shelloutput) private static string GetIpCommandOutput() { + var fileName = File.Exists(@"/usr/bin/ip") ? @"/usr/bin/ip" : + File.Exists(@"/usr/sbin/ip") ? @"/usr/sbin/ip" : + File.Exists(@"/sbin/ip") ? @"/sbin/ip" : + "ip"; + var ipResult = new ProcessStartInfo { - FileName = "ip", + FileName = fileName, Arguments = "link", UseShellExecute = false }.ExecuteAndCaptureOutput(out string ipStdOut, out string ipStdErr); @@ -87,7 +93,7 @@ private static string GetShellOutMacAddressOutput() { var result = new ProcessStartInfo { - FileName = "getmac.exe", + FileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "getmac.exe"), UseShellExecute = false }.ExecuteAndCaptureOutput(out string stdOut, out string stdErr); @@ -104,9 +110,14 @@ private static string GetShellOutMacAddressOutput() { try { + var fileName = File.Exists("/sbin/ifconfig") ? "/sbin/ifconfig" : + File.Exists("/usr/sbin/ifconfig") ? "/usr/sbin/ifconfig" : + File.Exists("/usr/bin/ifconfig") ? "/usr/bin/ifconfig" : + "ifconfig"; + var ifconfigResult = new ProcessStartInfo { - FileName = "ifconfig", + FileName = fileName, Arguments = "-a", UseShellExecute = false }.ExecuteAndCaptureOutput(out string ifconfigStdOut, out string ifconfigStdErr); diff --git a/src/Cli/dotnet/commands/dotnet-help/HelpCommand.cs b/src/Cli/dotnet/commands/dotnet-help/HelpCommand.cs index b3ef020f6fc5..60ca89861dc8 100644 --- a/src/Cli/dotnet/commands/dotnet-help/HelpCommand.cs +++ b/src/Cli/dotnet/commands/dotnet-help/HelpCommand.cs @@ -5,7 +5,7 @@ using System.CommandLine; using System.CommandLine.Parsing; using System.Diagnostics; -using System.Linq; +using System.IO; using Microsoft.DotNet.Cli; using Microsoft.DotNet.Cli.Utils; @@ -54,7 +54,7 @@ public static Process ConfigureProcess(string docUrl) { psInfo = new ProcessStartInfo { - FileName = "cmd", + FileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "cmd.exe"), Arguments = $"/c start {docUrl}" }; } @@ -62,15 +62,19 @@ public static Process ConfigureProcess(string docUrl) { psInfo = new ProcessStartInfo { - FileName = "open", + FileName = @"/usr/bin/open", Arguments = docUrl }; } else { + var fileName = File.Exists(@"/usr/bin/xdg-open") ? @"/usr/bin/xdg-open" : + File.Exists(@"/usr/sbin/xdg-open") ? @"/usr/sbin/xdg-open" : + File.Exists(@"/sbin/xdg-open") ? @"/sbin/xdg-open" : + "xdg-open"; psInfo = new ProcessStartInfo { - FileName = "xdg-open", + FileName = fileName, Arguments = docUrl }; } diff --git a/src/RazorSdk/Tool/ServerProtocol/ServerConnection.cs b/src/RazorSdk/Tool/ServerProtocol/ServerConnection.cs index a4fbc2f617d4..40ae032efe3f 100644 --- a/src/RazorSdk/Tool/ServerProtocol/ServerConnection.cs +++ b/src/RazorSdk/Tool/ServerProtocol/ServerConnection.cs @@ -288,7 +288,17 @@ internal static bool TryCreateServerCore(string clientDir, string pipeName, out // The server should be in the same directory as the client var expectedCompilerPath = Path.Combine(clientDir, ServerName); - var expectedPath = Environment.GetEnvironmentVariable("DOTNET_HOST_PATH") ?? "dotnet"; + + var expectedPath = Environment.GetEnvironmentVariable("DOTNET_HOST_PATH"); + if (string.IsNullOrEmpty(expectedPath)) + { +#if NET + expectedPath = System.Environment.ProcessPath; +#else + expectedPath = Process.GetCurrentProcess().MainModule.FileName; +#endif + } + var argumentList = new string[] { expectedCompilerPath, diff --git a/src/Tests/Microsoft.DotNet.CommandFactory.Tests/GivenAProjectPathCommandResolver.cs b/src/Tests/Microsoft.DotNet.CommandFactory.Tests/GivenAProjectPathCommandResolver.cs index 2f555ff3af56..13e52a919e5b 100644 --- a/src/Tests/Microsoft.DotNet.CommandFactory.Tests/GivenAProjectPathCommandResolver.cs +++ b/src/Tests/Microsoft.DotNet.CommandFactory.Tests/GivenAProjectPathCommandResolver.cs @@ -7,6 +7,7 @@ using FluentAssertions; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.CommandFactory; +using Microsoft.NET.TestFramework; using Xunit; namespace Microsoft.DotNet.Tests @@ -208,7 +209,7 @@ public void It_prefers_EXE_over_CMD_when_two_command_candidates_exist_and_using_ commandFile.Should().Be("projectpathtestcommand1.exe"); } - [Fact] + [WindowsOnlyFact] public void It_wraps_command_with_CMD_EXE_when_command_has_CMD_Extension_and_using_WindowsExePreferredCommandSpecFactory() { var environment = new EnvironmentProvider(new[] { ".cmd" }); @@ -231,7 +232,7 @@ public void It_wraps_command_with_CMD_EXE_when_command_has_CMD_Extension_and_usi result.Should().NotBeNull(); var commandFile = Path.GetFileName(result.Path); - commandFile.Should().Be("cmd.exe"); + commandFile.Should().EndWith("cmd.exe"); result.Args.Should().Contain(testCommandPath); } diff --git a/src/Tests/Microsoft.DotNet.CommandFactory.Tests/GivenAnAppBaseCommandResolver.cs b/src/Tests/Microsoft.DotNet.CommandFactory.Tests/GivenAnAppBaseCommandResolver.cs index f4976ef9ebfa..107bf767a823 100644 --- a/src/Tests/Microsoft.DotNet.CommandFactory.Tests/GivenAnAppBaseCommandResolver.cs +++ b/src/Tests/Microsoft.DotNet.CommandFactory.Tests/GivenAnAppBaseCommandResolver.cs @@ -7,6 +7,7 @@ using FluentAssertions; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.CommandFactory; +using Microsoft.NET.TestFramework; using Xunit; namespace Microsoft.DotNet.Tests @@ -153,7 +154,7 @@ public void It_prefers_EXE_over_CMD_when_two_command_candidates_exist_and_using_ commandFile.Should().Be("appbasetestcommand1.exe"); } - [Fact] + [WindowsOnlyFact] public void It_wraps_command_with_CMD_EXE_when_command_has_CMD_Extension_and_using_WindowsExePreferredCommandSpecFactory() { var environment = new EnvironmentProvider(new[] { ".cmd" }); @@ -175,7 +176,7 @@ public void It_wraps_command_with_CMD_EXE_when_command_has_CMD_Extension_and_usi result.Should().NotBeNull(); var commandFile = Path.GetFileName(result.Path); - commandFile.Should().Be("cmd.exe"); + commandFile.Should().EndWith("cmd.exe"); result.Args.Should().Contain(testCommandPath); } diff --git a/src/Tests/dotnet-help.Tests/GivenThatIWantToShowHelpForDotnetCommand.cs b/src/Tests/dotnet-help.Tests/GivenThatIWantToShowHelpForDotnetCommand.cs index 840ab0c1368b..f7b9046d3ad6 100644 --- a/src/Tests/dotnet-help.Tests/GivenThatIWantToShowHelpForDotnetCommand.cs +++ b/src/Tests/dotnet-help.Tests/GivenThatIWantToShowHelpForDotnetCommand.cs @@ -128,7 +128,7 @@ public void WhenCommandWithoutDocLinkIsPassedToDotnetHelpItPrintsError(string co public void WhenRunOnWindowsDotnetHelpCommandShouldContainProperProcessInformation() { var proc = HelpCommand.ConfigureProcess("https://aka.ms/dotnet-build"); - Assert.Equal("cmd", proc.StartInfo.FileName); + Assert.EndsWith("cmd.exe", proc.StartInfo.FileName); Assert.Equal("/c start https://aka.ms/dotnet-build", proc.StartInfo.Arguments); } @@ -144,7 +144,7 @@ public void WhenRunOnLinuxDotnetHelpCommandShouldContainProperProcessInformation public void WhenRunOnMacOsDotnetHelpCommandShouldContainProperProcessInformation() { var proc = HelpCommand.ConfigureProcess("https://aka.ms/dotnet-build"); - Assert.Equal("open", proc.StartInfo.FileName); + Assert.EndsWith("open", proc.StartInfo.FileName); Assert.Equal("https://aka.ms/dotnet-build", proc.StartInfo.Arguments); } } diff --git a/src/Tests/dotnet.Tests/dotnet-msbuild/GivenForwardingApp.cs b/src/Tests/dotnet.Tests/dotnet-msbuild/GivenForwardingApp.cs index 9ca72495a040..ca88504347af 100644 --- a/src/Tests/dotnet.Tests/dotnet-msbuild/GivenForwardingApp.cs +++ b/src/Tests/dotnet.Tests/dotnet-msbuild/GivenForwardingApp.cs @@ -17,14 +17,14 @@ public class GivenForwardingApp public void DotnetExeIsExecuted() { new ForwardingApp("", new string[0]) - .GetProcessStartInfo().FileName.Should().Be("dotnet.exe"); + .GetProcessStartInfo().FileName.Should().EndWith("dotnet.exe"); } [UnixOnlyFact] public void DotnetIsExecuted() { new ForwardingApp("", new string[0]) - .GetProcessStartInfo().FileName.Should().Be("dotnet"); + .GetProcessStartInfo().FileName.Should().EndWith("dotnet"); } [Fact] diff --git a/src/Tests/dotnet.Tests/dotnet-msbuild/GivenMsbuildForwardingApp.cs b/src/Tests/dotnet.Tests/dotnet-msbuild/GivenMsbuildForwardingApp.cs index c320b4f9c123..341acf2778f1 100644 --- a/src/Tests/dotnet.Tests/dotnet-msbuild/GivenMsbuildForwardingApp.cs +++ b/src/Tests/dotnet.Tests/dotnet-msbuild/GivenMsbuildForwardingApp.cs @@ -23,7 +23,7 @@ public void DotnetExeIsExecuted() { var msbuildPath = ""; new MSBuildForwardingApp(new string[0], msbuildPath) - .GetProcessStartInfo().FileName.Should().Be("dotnet.exe"); + .GetProcessStartInfo().FileName.Should().EndWith("dotnet.exe"); } [UnixOnlyFact] @@ -31,7 +31,7 @@ public void DotnetIsExecuted() { var msbuildPath = ""; new MSBuildForwardingApp(new string[0], msbuildPath) - .GetProcessStartInfo().FileName.Should().Be("dotnet"); + .GetProcessStartInfo().FileName.Should().EndWith("dotnet"); } [Theory]