Skip to content

Commit f1f9ac3

Browse files
authored
Repair Repair-WinGetPackageManager (microsoft#5568)
`Repair-WinGetPackageManager` is failing to install winget in some Win10 systems. The issue seems come from microsoft#5517 and be caused because in some cases we fail to mark any one architecture as the right one to use for dependencies. This PR is a partial revert of microsoft#5517 to add the previous logic as a fallback. May fix microsoft#5559 (but I haven't set up an environment to test it...) ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/microsoft/winget-cli/pull/5568)
1 parent eb03885 commit f1f9ac3

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)