diff --git a/Tasks/UseDotNetV2/externals/get-os-platform.ps1 b/Tasks/UseDotNetV2/externals/get-os-platform.ps1 index 4ac8d07f5ba4..f6153539d2b4 100644 --- a/Tasks/UseDotNetV2/externals/get-os-platform.ps1 +++ b/Tasks/UseDotNetV2/externals/get-os-platform.ps1 @@ -1,16 +1,35 @@ -function Get-Machine-Architecture() -{ - # possible values: AMD64, IA64, x86 +function Get-Machine-Architecture() { + # On PS x86, PROCESSOR_ARCHITECTURE reports x86 even on x64 systems. + # To get the correct architecture, we need to use PROCESSOR_ARCHITEW6432. + # PS x64 doesn't define this, so we fall back to PROCESSOR_ARCHITECTURE. + # Possible values: amd64, x64, x86, arm64, arm + if( $ENV:PROCESSOR_ARCHITEW6432 -ne $null ) { + return $ENV:PROCESSOR_ARCHITEW6432 + } + + try { + if( ((Get-CimInstance -ClassName CIM_OperatingSystem -OperationTimeoutSec 30).OSArchitecture) -like "ARM*") { + if( [Environment]::Is64BitOperatingSystem ) + { + return "arm64" + } + return "arm" + } + } + catch { + # Machine doesn't support Get-CimInstance + } + return $ENV:PROCESSOR_ARCHITECTURE } -function Get-CLIArchitecture-From-Architecture([string]$Architecture) -{ - switch ($Architecture.ToLower()) - { +function Get-CLIArchitecture-From-Architecture([string]$Architecture) { + switch ($Architecture.ToLowerInvariant()) { { ($_ -eq "amd64") -or ($_ -eq "x64") } { return "x64" } { $_ -eq "x86" } { return "x86" } - default { throw "Architecture not supported. If you think this is a bug, please report it at https://github.com/dotnet/cli/issues" } + { $_ -eq "arm" } { return "arm" } + { $_ -eq "arm64" } { return "arm64" } + default { throw "Architecture '$Architecture' not supported. If you think this is a bug, report it at https://github.com/microsoft/azure-pipelines-tasks/issues" } } } diff --git a/Tasks/UseDotNetV2/task.json b/Tasks/UseDotNetV2/task.json index 7ab9cc97a88b..aaecd4d3fedb 100644 --- a/Tasks/UseDotNetV2/task.json +++ b/Tasks/UseDotNetV2/task.json @@ -13,7 +13,7 @@ "author": "Microsoft Corporation", "version": { "Major": 2, - "Minor": 248, + "Minor": 249, "Patch": 0 }, "satisfies": [ diff --git a/Tasks/UseDotNetV2/task.loc.json b/Tasks/UseDotNetV2/task.loc.json index 65944cef02c9..c5378f9766b2 100644 --- a/Tasks/UseDotNetV2/task.loc.json +++ b/Tasks/UseDotNetV2/task.loc.json @@ -13,7 +13,7 @@ "author": "Microsoft Corporation", "version": { "Major": 2, - "Minor": 248, + "Minor": 249, "Patch": 0 }, "satisfies": [