Skip to content

PowerShell installed as a .NET global tool cannot invoke its own CLI on macOS #12205

Closed

Description

When PowerShell is installed as a .NET global tool, it prepends its own $PSHOME folder to $env:PATH.

However, on macOS $PSHOME contains an incompatible pwsh binary that is for Linux.

Therefore, from within an existing session, invoking pwsh (by mere file name) unexpectedly fails.

Steps to reproduce

# Install PowerShell as a .NET global tool, to ~/.dotnet/tools
dotnet tool install powershell -g

# Invoke it, and try to re-invoke its own CLI.
~/.dotnet/tools/pwsh -noprofile -c 'pwsh -noprofile -c write-output hi' | Should -Be 'hi'

Expected behavior

The test should succeed.

Actual behavior

The test fails, due to incompatible binary being invoked:

Expected 'hi', but got @('ResourceUnavailable: Program 'pwsh' failed to run: Exec format errorAt line:1 char:1' ...

Environment data

PowerShell Core v7.0.0 (7.0.0) on macOS 10.15.3

Activity

  1. added
    Issue-Question
    on Mar 25, 2020
  2. added
    WG-Maintainers-Build
    Issue-Bug
    and removed
    Issue-Question
    on Mar 25, 2020
  3. mklement0 commented on Mar 26, 2020

    @mklement0
    Author
  4. TravisEz13 commented on Apr 7, 2020

    @TravisEz13
    Member

    I verified this behavior on 7.0.0 on macOS 10.15.4

  5. albigi commented on Dec 30, 2020

    @albigi

    this is still a problem on macOS 11.1 and it can be quite unpleasant when deploying xplat scripts. I would expect that invoking a child pwsh would work under every circumstance

  6. kkshinkai commented on Jul 28, 2021

    @kkshinkai

    Any progress on this?

    #11141 puts $PSHOME at the front of $PATH, so this problem becomes unsolvable under macOS. Perhaps we should put $PSHOME at the end of the $PATH.

  7. ins0mniaque commented on Mar 13, 2022

    @ins0mniaque

    This is still a problem on macOS 12.2.1 (arm64).

    I can confirm that having $PSHOME in front of $PATH (#11141) makes it impossible to fix using $Env:Path under macOS.

    As a workaround, I added this to my PowerShell profile:

    Set-Alias pwsh "~/.dotnet/tools/pwsh"
    
  8. StevenBucher98 commented on Sep 26, 2022

    @StevenBucher98
    Collaborator

    Looks like possibly another issue reported around this bug, #18139

  9. dlnash18 commented on Oct 7, 2022

    @dlnash18

    Steven Bucher (@StevenBucher98): Thanks for connecting the dots. Yep, looks like the same bug to me. Knowing about #11141 explains why changing $PATH didn't fix the problem for me. The workaround I mentioned in my bug is very simple:

    cd $PSHOME
    mv pwsh pwsh.elf
    ln -s ../../../../../../../../../../../.dotnet/tools/pwsh pwsh
    

    It fixes this bug as well, unsurprisingly. I've been running in this state since I posted my bug and have yet to notice any adverse effects.

  10. lukket commented on Jun 12, 2023

    @lukket

    It's now 2023, macOS 13.4, PowerShell 7.3.4 and this is still an issue...

    Thanks for the workaround Donald Nash (@dlnash18).

  11. added
    Resolution-No Activity
    on Dec 9, 2023
  12. microsoft-github-policy-service commented on Dec 9, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if there is no further activity in 7 days, the issue will be closed automatically.

    Activity in this case refers only to comments on the issue. If the issue is closed and you are the author, you can re-open the issue using the button below. Please add more information to be considered during retriage. If you are not the author but the issue is impacting you after it has been closed, please submit a new issue with updated details and a link to this issue and the original.

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

Metadata

Metadata

Labels

Issue-BugResolution-No ActivityWG-Maintainers-Build

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions