taskman_dotnet/dotnet.inc.php

92 lines
1.7 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");
}
}
2024-09-23 19:02:14 +03:00
task('dotnet_set_env', ['always' => true], function() {
dotnet_set_env();
2024-09-23 18:27:20 +03:00
});
task('dotnet_install', function() {
DotnetSupport::install();
});
function dotnet_shell($cmd)
{
shell('dotnet ' . $cmd);
}
function dotnet_shell_get($cmd)
{
return shell_get('dotnet ' . $cmd);
}
2024-09-23 18:27:20 +03:00
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");
}
2024-09-23 19:02:14 +03:00
function dotnet_set_env()
2024-09-23 18:27:20 +03:00
{
2024-09-23 19:02:14 +03:00
putenv("DOTNET_CLI_TELEMETRY_OPTOUT=1");
2024-09-23 18:27:20 +03:00
$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";
}