true], function() { dotnet_set_env(); }); 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() { putenv("DOTNET_CLI_TELEMETRY_OPTOUT=1"); $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"; }