From 6afdf3efe1d621a07577e4f54526ed5ddd3041eb Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Sun, 10 Apr 2022 16:13:48 +0100 Subject: [PATCH] Ensure dotnet is on the PATH for the remote PowerShell host VS Mac 17.0 creates the pad windows when the IDE window is first shown, even if the pad is never opened or available docked. This means the PATH used to launch the powershell console host does not contain the path to the dotnet CLI which is configured when a project is opened. To avoid this check for a valid dotnet runtime and set the PATH for the powershell console host to be the parent process's PATH environment variable with the path to dotnet appended. --- .../RemotePowerShellHost.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/MonoDevelop.PackageManagement.Extensions/MonoDevelop.PackageManagement.Scripting/RemotePowerShellHost.cs b/src/MonoDevelop.PackageManagement.Extensions/MonoDevelop.PackageManagement.Scripting/RemotePowerShellHost.cs index 614f457..610ba8c 100644 --- a/src/MonoDevelop.PackageManagement.Extensions/MonoDevelop.PackageManagement.Scripting/RemotePowerShellHost.cs +++ b/src/MonoDevelop.PackageManagement.Extensions/MonoDevelop.PackageManagement.Scripting/RemotePowerShellHost.cs @@ -121,6 +121,8 @@ static Process StartPowerShellHost () RedirectStandardOutput = true }; + ConfigurePathEnvironmentVariable (info); + var process = new Process { StartInfo = info }; @@ -129,6 +131,27 @@ static Process StartPowerShellHost () return process; } + /// + /// Ensure dotnet is on the PATH. + /// + static void ConfigurePathEnvironmentVariable (ProcessStartInfo info) + { + if (DotNetCoreRuntime.IsMissing) { + return; + } + + string dotNetDirectory = Path.GetDirectoryName (DotNetCoreRuntime.FileName); + if (string.IsNullOrEmpty (dotNetDirectory)) { + return; + } + + string path = Environment.GetEnvironmentVariable ("PATH"); + if (!string.IsNullOrEmpty (path)) { + path += Path.PathSeparator + dotNetDirectory; + info.EnvironmentVariables ["PATH"] = path; + } + } + void JsonRpcDisconnected (object sender, JsonRpcDisconnectedEventArgs e) { string errorMessage = GettextCatalog.GetString (