Skip to content

Commit a53cd97

Browse files
committed
Add fallback
1 parent 26e5eca commit a53cd97

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/PowerShell/Microsoft.WinGet.Client.Engine/Helpers/AppxModuleHelper.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ private HashSet<Architecture> InitFrameworkArchitectures()
357357
{
358358
HashSet<Architecture> architectures = new HashSet<Architecture>();
359359

360+
// Read the override from the environment variable if it exists.
360361
string? environmentVariable = Environment.GetEnvironmentVariable(DependencyArchitectureEnvironmentVariable);
361362
if (environmentVariable != null)
362363
{
@@ -377,6 +378,7 @@ private HashSet<Architecture> InitFrameworkArchitectures()
377378
return architectures;
378379
}
379380

381+
// If there are any framework packages already installed, use the same architecture as them.
380382
var result = this.ExecuteAppxCmdlet(
381383
GetAppxPackage,
382384
new Dictionary<string, object>
@@ -406,6 +408,31 @@ private HashSet<Architecture> InitFrameworkArchitectures()
406408
}
407409
}
408410

411+
// Fall back to guessing from the current OS architecture.
412+
// This may have issues on ARM64 because RuntimeInformation.OSArchitecture seems to just lie sometimes.
413+
// See https://github.com/microsoft/winget-cli/issues/5020
414+
if (architectures.Count == 0)
415+
{
416+
var arch = RuntimeInformation.OSArchitecture;
417+
this.pwshCmdlet.Write(StreamType.Verbose, $"OS architecture: {arch.ToString()}");
418+
419+
if (arch == Architecture.X64)
420+
{
421+
architectures.Add(Architecture.X64);
422+
}
423+
else if (arch == Architecture.X86)
424+
{
425+
architectures.Add(Architecture.X86);
426+
}
427+
else if (arch == Architecture.Arm64)
428+
{
429+
// Let deployment figure it out
430+
architectures.Add(Architecture.Arm64);
431+
architectures.Add(Architecture.X64);
432+
architectures.Add(Architecture.X86);
433+
}
434+
}
435+
409436
return architectures;
410437
}
411438

0 commit comments

Comments
 (0)