diff --git a/src/PowerShell/Microsoft.WinGet.Client.Engine/Helpers/AppxModuleHelper.cs b/src/PowerShell/Microsoft.WinGet.Client.Engine/Helpers/AppxModuleHelper.cs index 79f14f86bb..e8b8d1ad09 100644 --- a/src/PowerShell/Microsoft.WinGet.Client.Engine/Helpers/AppxModuleHelper.cs +++ b/src/PowerShell/Microsoft.WinGet.Client.Engine/Helpers/AppxModuleHelper.cs @@ -357,6 +357,7 @@ private HashSet InitFrameworkArchitectures() { HashSet architectures = new HashSet(); + // Read the override from the environment variable if it exists. string? environmentVariable = Environment.GetEnvironmentVariable(DependencyArchitectureEnvironmentVariable); if (environmentVariable != null) { @@ -377,6 +378,7 @@ private HashSet InitFrameworkArchitectures() return architectures; } + // If there are any framework packages already installed, use the same architecture as them. var result = this.ExecuteAppxCmdlet( GetAppxPackage, new Dictionary @@ -406,6 +408,31 @@ private HashSet InitFrameworkArchitectures() } } + // Fall back to guessing from the current OS architecture. + // This may have issues on ARM64 because RuntimeInformation.OSArchitecture seems to just lie sometimes. + // See https://github.com/microsoft/winget-cli/issues/5020 + if (architectures.Count == 0) + { + var arch = RuntimeInformation.OSArchitecture; + this.pwshCmdlet.Write(StreamType.Verbose, $"OS architecture: {arch.ToString()}"); + + if (arch == Architecture.X64) + { + architectures.Add(Architecture.X64); + } + else if (arch == Architecture.X86) + { + architectures.Add(Architecture.X86); + } + else if (arch == Architecture.Arm64) + { + // Let deployment figure it out + architectures.Add(Architecture.Arm64); + architectures.Add(Architecture.X64); + architectures.Add(Architecture.X86); + } + } + return architectures; }