Handle MSIX installation specially when prepend to PATH - #27782
Draft
Dongbo Wang (daxian-dbw) wants to merge 2 commits into
Draft
Handle MSIX installation specially when prepend to PATH#27782Dongbo Wang (daxian-dbw) wants to merge 2 commits into
Dongbo Wang (daxian-dbw) wants to merge 2 commits into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts how ConsoleHost prepends the PowerShell executable location to PATH at startup, with special handling for MSIX installs so that pwsh resolves to a stable path (not a versioned MSIX package folder), preventing downstream tools (e.g., CMake) from caching an update-volatile path.
Changes:
- Replace
$PSHOME-based PATH prepending with a computed “pwsh executable home” viaGetPSExecutableHome(). - Add MSIX-specific path stabilization (
ResolveStablePathIfMsix) to prefer the WindowsApps execution-alias directory over the versioned package directory. - Update the console host PATH test to invoke
pwsh -v(via command resolution) instead of invoking the known$powershellpath directly.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs |
Computes the executable home path for PATH-prepending and adds MSIX-specific stable-path resolution. |
test/powershell/Host/ConsoleHost.Tests.ps1 |
Adjusts the PATH behavior test to validate pwsh command resolution matches the current running build. |
Comment on lines
+383
to
+388
| string psExePath = Environment.ProcessPath; | ||
| string psExeHome = Path.GetDirectoryName(psExePath); | ||
| string processName = Path.GetFileName(psExePath); | ||
|
|
||
| // Use 'Environment.ProcessPath' if it points to 'pwsh.exe' or 'pwsh'. | ||
| if (pwshName.Equals(processName, StringComparison.Ordinal)) |
Comment on lines
+442
to
+444
| /// That path contains a version string and will change with every update. Prepend that path to the PATH environment variable | ||
| /// caused a problem to the cmake-based build system, where cmake cached the path to 'pwsh.exe' when running for the 1st time | ||
| /// from the MSIX PowerShell. That cached path became invalid after the MSIX PowerShell got updated, which broke cmake. |
12 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Prepend
$PSHOMEtoPATHenv variable at startup causes a problem to cmake-based build system when it runs in the MSIX PowerShell installation because it caches the location of PowerShell on its first run from within PowerShell.At startup, PowerShell adds
$PSHOMEto the beginning ofPATH, and for MSIX installation,$PSHOMEcontains version numbers that change when PowerShell is updated.When
cmakeis started for the 1st time from MSIX PowerShell, the path it caches will be that$PSHOME, which will become invalid after an update of the MSIX PowerShell.PR Summary
This PR updated the code that prepend
$PSHOMEtoPATH. It now handles the MSIX package installation specially -- it uses the directory that contains theExecutionAliasof the MSIX installation instead of$PSHOME. For example:Those are the stable paths that contain the
pwsh.exealias pointing to corresponding channels of MSIX. They won't change when the MSIX packages get updated.PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header