Skip to content

Conversation

@daxian-dbw
Copy link
Member

PR Summary

Fix #24090

Handle global tool specially when prepending PSHome to the PATH environment variable.
When running PowerShell global tool, the real entry executable should be the pwsh or pwsh.exe within the '../.dotnet/tools' folder, not what PSHome is pointing to.

PR Checklist

@daxian-dbw daxian-dbw requested a review from anmenaga as a code owner August 29, 2024 17:30
@daxian-dbw daxian-dbw added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Aug 29, 2024
@daxian-dbw
Copy link
Member Author

@adityapatwardhan I think we should not include the pwsh executable file in the any\unix and any\win folders, because there are only those 2 folders in the global tool, and you just cannot cover all the architecture flavors.

I guess the pwsh/pwsh.exe executable was added because there was complaint about $pshome\pwsh doesn't work? I think it's by design with the global tool installation. And with this change, the workaround would be to run pwsh directly which is guaranteed to be the same global tool executable (under .../.dotnet/tools)

// We're running PowerShell global tool. In this case the real entry executable should be the 'pwsh'
// or 'pwsh.exe' within the '../.dotnet/tools' folder, not what PSHome is pointing to.
// BTW, 13 is the length of '.dotnet/tools'
pshome = pshome[0..(index + 13)];
Copy link
Member

Choose a reason for hiding this comment

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

this is true for global tools that are installed globally with dotnet tool install -g. It can be installed to any path, but I agree that most people will install it globally. Maybe add this to comments.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, thanks! I've updated the code to cover the scenario where the PowerShell global tool is installed to an arbitrary location.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Review - Needed The PR is being reviewed label Sep 6, 2024
@daxian-dbw daxian-dbw added BackPort-7.5.x-Consider MustHave and removed Review - Needed The PR is being reviewed labels Sep 9, 2024
@daxian-dbw daxian-dbw merged commit 7e27e63 into PowerShell:master Sep 10, 2024
@daxian-dbw daxian-dbw deleted the env branch September 10, 2024 20:01
chrisdent-de pushed a commit to chrisdent-de/PowerShell that referenced this pull request Sep 12, 2024
adityapatwardhan pushed a commit to adityapatwardhan/PowerShell that referenced this pull request Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BackPort-7.5.x-Done CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log MustHave

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pwsh corrupts PATH environment variable, breaking nested invocations on everything that isn't x86-64

2 participants