Skip to content

Move all PS CLI use to packaged path - #6727

Open
JohnMcPMS wants to merge 4 commits into
microsoft:masterfrom
JohnMcPMS:use-pkg-path
Open

JohnMcPMS wants to merge 4 commits into
microsoft:masterfrom
JohnMcPMS:use-pkg-path

Conversation

@JohnMcPMS

@JohnMcPMS JohnMcPMS commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

📖 Description

Move all CLI calling cmdlets to use the packaged path.
Move to using OS APIs to find it so we can do it without piping an invocation around.

🔍 Validation

Kept largely as is, but I did make the package discovery code run in dev mode even if we do end up needing to use the alias to run it (directly running packaged exes only runs them "packaged" when an access-denied error triggers a remediation path).

Microsoft Reviewers: Open in CodeFlow

@JohnMcPMS
JohnMcPMS requested a review from a team as a code owner December 3, 2026 02:07
Copilot AI balanced review requested due to automatic review settings December 3, 2026 02:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical issues leave CLI commands using a stale executable path after version changes and cause repair to attempt registration instead of installing a trusted package when only a developer-signed package is present.

2 open issues
What changed in this PR

Moves PowerShell CLI-backed commands to centralized WinGet package discovery through Windows APIs, using the Store-signed executable in production while retaining alias activation for development.

Changes:

  • Centralizes executable resolution and updates CLI callers.
  • Adds Windows API projections and adjusts integrity checks and tests.
  • Updates the release note to cover all CLI-backed commands.
File Description
src/​PowerShell/​tests/​RunTests.ps1 Narrows Pester test selection.
src/​PowerShell/​tests/​Microsoft.WinGet.Client.Integrity.Tests.ps1 Removes mocked integrity tests.
src/​PowerShell/​Microsoft.WinGet.UnitTests/​WinGetIntegrityTests.cs Removes the obsolete constructor test.
src/​PowerShell/​Microsoft.WinGet.UnitTests/​WingetCLIWrapperTests.cs Moves trust-filter tests to the wrapper.
src/​PowerShell/​Microsoft.WinGet.UnitTests/​Microsoft.WinGet.UnitTests.csproj Adds an engine reference alias.
src/​PowerShell/​Microsoft.WinGet.Client.Engine/​Microsoft.WinGet.Client.Engine.csproj Adds package-discovery API projections.
src/​PowerShell/​Microsoft.WinGet.Client.Engine/​Helpers/​WinGetVersion.cs Uses centralized executable resolution.
src/​PowerShell/​Microsoft.WinGet.Client.Engine/​Helpers/​WingetCLIWrapper.cs Discovers and caches the packaged executable path.
src/​PowerShell/​Microsoft.WinGet.Client.Engine/​Helpers/​AppxModuleHelper.cs Removes trust-filtered PowerShell discovery.
src/​PowerShell/​Microsoft.WinGet.Client.Engine/​Common/​WinGetIntegrity.cs Updates executable and diagnostic lookups.
src/​PowerShell/​Microsoft.WinGet.Client.Engine/​Commands/​UserSettingsCommand.cs Uses the parameterless CLI wrapper.
src/​PowerShell/​Microsoft.WinGet.Client.Engine/​Commands/​CliCommand.cs Uses the parameterless CLI wrapper.
doc/​release-notes/​1.31/​powershell-winget-path-resolution.md Broadens the path-resolution release note.

Review effort: Balanced

#if USE_PROD_CLSIDS
string? version = appxModule.GetStoreSignedAppInstallerPropertyValue("Version");
#else
string? version = appxModule.GetAppInstallerPropertyValue("Version");
/// <summary>
/// Gets the cached path to the installed WinGet executable.
/// </summary>
public static string WinGetFullPath => LazyInitializer.EnsureInitialized(ref winGetFullPath, GetWinGetPath) !;

@ranm-msft ranm-msft left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One repair-path regression to address before approval.

/// <summary>
/// Gets the cached path to the installed WinGet executable.
/// </summary>
public static string WinGetFullPath => LazyInitializer.EnsureInitialized(ref winGetFullPath, GetWinGetPath) !;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WinGetFullPath caches a versioned WindowsApps path for the PowerShell process lifetime. RepairStateMachineAsync resolves it before deploying a different App Installer version, then re-enters AssertWinGet with the stale path, so the repair reruns the old binary or fails after its removal. Please re-resolve after deployment or avoid caching, and test a version-changing repair followed by another CLI command in the same session.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants