Setting proper dotnet PATH during installation detection
This commit is contained in:
parent
f9d5dd6b9e
commit
e9d5e8468f
|
@ -22,11 +22,8 @@ function dotnet_shell_get($cmd)
|
||||||
|
|
||||||
function dotnet_set_env()
|
function dotnet_set_env()
|
||||||
{
|
{
|
||||||
|
//TODO: do we need this one?
|
||||||
putenv("DOTNET_CLI_TELEMETRY_OPTOUT=1");
|
putenv("DOTNET_CLI_TELEMETRY_OPTOUT=1");
|
||||||
|
|
||||||
$dotnet_path = DotnetSupport::getPath();
|
DotnetSupport::addEnvPath();
|
||||||
if(is_win())
|
|
||||||
putenv("PATH=$dotnet_path;".getenv('PATH'));
|
|
||||||
else
|
|
||||||
putenv("PATH=$dotnet_path:".getenv('PATH'));
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ class DotnetSupport
|
||||||
$has_dotnet = true;
|
$has_dotnet = true;
|
||||||
|
|
||||||
$dotnet_curr_ver = "";
|
$dotnet_curr_ver = "";
|
||||||
|
$prev_path = self::addEnvPath();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$dotnet_curr_ver = self::shellGet("dotnet --version");
|
$dotnet_curr_ver = self::shellGet("dotnet --version");
|
||||||
|
@ -23,6 +24,10 @@ class DotnetSupport
|
||||||
{
|
{
|
||||||
$has_dotnet = false;
|
$has_dotnet = false;
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
self::setEnvPath($prev_path);
|
||||||
|
}
|
||||||
|
|
||||||
if($has_dotnet && version_compare($dotnet_curr_ver, $version) >= 0)
|
if($has_dotnet && version_compare($dotnet_curr_ver, $version) >= 0)
|
||||||
return;
|
return;
|
||||||
|
@ -34,9 +39,9 @@ class DotnetSupport
|
||||||
$version_parts = explode('.', $version);
|
$version_parts = explode('.', $version);
|
||||||
$channel = $version_parts[0].'.'.$version_parts[1];
|
$channel = $version_parts[0].'.'.$version_parts[1];
|
||||||
if(self::isWin())
|
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
|
else
|
||||||
self::Shell("\"$install_file_path\" --channel $channel");
|
self::shell("\"$install_file_path\" --channel $channel");
|
||||||
}
|
}
|
||||||
|
|
||||||
static function getInstallerPath() : string
|
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
|
static function isWin() : bool
|
||||||
{
|
{
|
||||||
return !(DIRECTORY_SEPARATOR == '/');
|
return !(DIRECTORY_SEPARATOR == '/');
|
||||||
|
|
Loading…
Reference in New Issue