From e9d5e8468ffb6339f4aac90ef09b7f81ae596912 Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Wed, 20 Nov 2024 09:25:46 +0300 Subject: [PATCH] Setting proper dotnet PATH during installation detection --- dotnet.inc.php | 7 ++----- support.inc.php | 29 +++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/dotnet.inc.php b/dotnet.inc.php index 6c05699..5278718 100644 --- a/dotnet.inc.php +++ b/dotnet.inc.php @@ -22,11 +22,8 @@ function dotnet_shell_get($cmd) function dotnet_set_env() { + //TODO: do we need this one? putenv("DOTNET_CLI_TELEMETRY_OPTOUT=1"); - $dotnet_path = DotnetSupport::getPath(); - if(is_win()) - putenv("PATH=$dotnet_path;".getenv('PATH')); - else - putenv("PATH=$dotnet_path:".getenv('PATH')); + DotnetSupport::addEnvPath(); } diff --git a/support.inc.php b/support.inc.php index 722dd81..d51ab60 100644 --- a/support.inc.php +++ b/support.inc.php @@ -14,6 +14,7 @@ class DotnetSupport $has_dotnet = true; $dotnet_curr_ver = ""; + $prev_path = self::addEnvPath(); try { $dotnet_curr_ver = self::shellGet("dotnet --version"); @@ -23,6 +24,10 @@ class DotnetSupport { $has_dotnet = false; } + finally + { + self::setEnvPath($prev_path); + } if($has_dotnet && version_compare($dotnet_curr_ver, $version) >= 0) return; @@ -34,9 +39,9 @@ class DotnetSupport $version_parts = explode('.', $version); $channel = $version_parts[0].'.'.$version_parts[1]; if(self::isWin()) - self::Shell("powershell -NoProfile -ExecutionPolicy unrestricted Invoke-Expression '\"$install_file_path\" -Channel $channel'"); + self::shell("powershell -NoProfile -ExecutionPolicy unrestricted Invoke-Expression '\"$install_file_path\" -Channel $channel'"); else - self::Shell("\"$install_file_path\" --channel $channel"); + self::shell("\"$install_file_path\" --channel $channel"); } static function getInstallerPath() : string @@ -60,6 +65,26 @@ class DotnetSupport } } + static function addEnvPath(string $path = '') : string + { + $prev_path = getenv('PATH'); + + if(!$path) + $path = DotnetSupport::getPath(); + + if(self::isWin()) + self::setEnvPath("$path;$prev_path"); + else + self::setEnvPath("$path:$prev_path"); + + return $prev_path; + } + + static function setEnvPath(string $path) + { + putenv("PATH=$path"); + } + static function isWin() : bool { return !(DIRECTORY_SEPARATOR == '/');