diff --git a/dist/index.js b/dist/index.js index d897c56a4..553f9911e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -275,7 +275,7 @@ class DotnetCoreInstaller { command += ` -ProxyBypassList ${process.env['no_proxy']}`; } // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used - const powershellPath = yield io.which('powershell', true); + const powershellPath = (yield io.which('pwsh', false)) || (yield io.which('powershell', true)); var options = { listeners: { stdout: (data) => { diff --git a/externals/install-dotnet.sh b/externals/install-dotnet.sh index 55f43507c..3e16cc9da 100755 --- a/externals/install-dotnet.sh +++ b/externals/install-dotnet.sh @@ -353,6 +353,48 @@ get_normalized_architecture_from_architecture() { return 1 } +# args: +# version - $1 +# channel - $2 +# architecture - $3 +get_normalized_architecture_for_specific_sdk_version() { + eval $invocation + + local is_version_support_arm64="$(is_arm64_supported "$1")" + local is_channel_support_arm64="$(is_arm64_supported "$2")" + local architecture="$3"; + local osname="$(get_current_os_name)" + + if [ "$osname" == "osx" ] && [ "$architecture" == "arm64" ] && { [ "$is_version_support_arm64" = false ] || [ "$is_channel_support_arm64" = false ]; }; then + #check if rosetta is installed + if [ "$(/usr/bin/pgrep oahd >/dev/null 2>&1;echo $?)" -eq 0 ]; then + say_verbose "Changing user architecture from '$architecture' to 'x64' because .NET SDKs prior to version 6.0 do not support arm64." + echo "x64" + return 0; + else + say_err "Architecture \`$architecture\` is not supported for .NET SDK version \`$version\`. Please install Rosetta to allow emulation of the \`$architecture\` .NET SDK on this platform" + return 1 + fi + fi + + echo "$architecture" + return 0 +} + +# args: +# version or channel - $1 +is_arm64_supported() { + #any channel or version that starts with the specified versions + case "$1" in + ( "1"* | "2"* | "3"* | "4"* | "5"*) + echo false + return 0 + esac + + echo true + return 0 +} + # args: # user_defined_os - $1 get_normalized_os() { @@ -523,7 +565,7 @@ parse_globaljson_file_for_version() { return 1 fi - sdk_section=$(cat $json_file | awk '/"sdk"/,/}/') + sdk_section=$(cat $json_file | tr -d "\r" | awk '/"sdk"/,/}/') if [ -z "$sdk_section" ]; then say_err "Unable to parse the SDK node in \`$json_file\`" return 1 @@ -988,8 +1030,6 @@ download() { sleep $((attempts*10)) done - - if [ "$failed" = true ]; then say_verbose "Download failed: $remote_path" return 1 @@ -1346,6 +1386,8 @@ calculate_vars() { install_root="$(resolve_installation_path "$install_dir")" say_verbose "InstallRoot: '$install_root'." + normalized_architecture="$(get_normalized_architecture_for_specific_sdk_version "$version" "$normalized_channel" "$normalized_architecture")" + if [[ "$runtime" == "dotnet" ]]; then asset_relative_path="shared/Microsoft.NETCore.App" asset_name=".NET Core Runtime" diff --git a/src/installer.ts b/src/installer.ts index c25d23a0a..d5911d9f2 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -116,7 +116,8 @@ export class DotnetCoreInstaller { } // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used - const powershellPath = await io.which('powershell', true); + const powershellPath = + (await io.which('pwsh', false)) || (await io.which('powershell', true)); var options: ExecOptions = { listeners: {