taskman_dotnet/dotnet.inc.php

80 lines
1.6 KiB
PHP
Raw Normal View History

2024-09-23 18:27:20 +03:00
<?php
namespace taskman;
class DotnetSupport
{
static function install()
{
dotnet_install("8.0.0");
}
}
task('dotnet_set_env_path', ['always' => true], function() {
dotnet_set_env_path();
});
task('dotnet_install', function() {
DotnetSupport::install();
});
function dotnet_install(string $version)
{
$has_dotnet = true;
$dotnet_curr_ver = "";
try
{
$dotnet_curr_ver = shell_get("dotnet --version");
print("DOTNET CURRENT VERSION: $dotnet_curr_ver\n");
}
catch(\Throwable $th)
{
$has_dotnet = false;
}
if($has_dotnet && version_compare($dotnet_curr_ver, $version) >= 0)
return;
print("DOTNET VERSION MISMATCH: $dotnet_curr_ver < $version\n");
$install_file_path = dotnet_get_installer_path();
$version_parts = explode('.', $version);
$channel = $version_parts[0].'.'.$version_parts[1];
if(is_win())
shell("powershell -NoProfile -ExecutionPolicy unrestricted Invoke-Expression '\"$install_file_path\" -Channel $channel'");
else
shell("\"$install_file_path\" --channel $channel");
}
function dotnet_set_env_path()
{
$dotnet_path = dotnet_get_path();
if(is_win())
putenv("PATH=$dotnet_path;".getenv('PATH'));
else
putenv("PATH=$dotnet_path:".getenv('PATH'));
}
function dotnet_get_path()
{
if(is_win())
{
$appdata_path = getenv('LOCALAPPDATA');
return "$appdata_path\\Microsoft\\dotnet\\";
}
else
{
return getenv("HOME")."/.dotnet/";
}
}
function dotnet_get_installer_path() : string
{
if(is_win())
return __DIR__ . "/dotnet-install.ps1";
else
return __DIR__ . "/dotnet-install.sh";
}