@@ -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