question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

macOS dotnet CLI path for global tools is bad - Installer issue

See original GitHub issue

Describe the bug

On macOS when a .Net tool is installed globally, it will not be found in the PATH.

The dotnet installer does attempt to make the directory for globally installed tools part of the PATH, but the mechanism the installer is relying on doesn’t work as the installer apparently expects.

To Reproduce

  1. Install dotnet on macOS using the Microsoft Installer from https://dotnet.microsoft.com/en-us/download.
  2. Install a tool globally, e.g. dotnet tool install -g Microsoft.dotnet-httprepl
  3. Assuming zsh which is the default shell on macOS (Catalina and newer), run the command which httprepl
  4. The output of the which command will be “httprepl not found” indicating that the httprepl tool can’t be found in the PATH.

Further technical details

Why does this happen?

macOS has a mechanism for adding paths to the PATH environment variable. The files in /etc/paths.d are used by the path_helper tool to build up the PATH environment variable.

The installer for dotnet is adding two files for paths:

  • /etc/paths.d/dotnet
  • /etc/paths.d/dotnet-cli-tools

The dotnet file contains

/usr/local/share/dotnet

The dotnet-cli-tools file contains

~/.dotnet/tools

However, paths in these files should be literal. The tilde (~) is not expanded to be the current user home directory. Environment variable references are also not expanded.

bash

The default standard shell on macOS Catalina (released in 2019) and newer is zsh. Prior to Catalina the default standard shell was bash. The bash shell appears to expand the tilde at a later point for an interactive shell so this issue may not manifest for bash users. However, the files created in /etc/paths.d by the dotnet installer need to support all shells.

Can’t Specify the Current User Home Directory

The tilde can’t be expected to be expanded to be the current user home directory. ${HOME} also can’t be used. There is not a way to specify the current user home directory in a file in /etc/paths.d.

I don’t know if not supporting the current user home directory is by design or is an omission.

Given the current functionality, the dotnet installer should not create the /etc/paths.d/dotnet-cli-tools file at all.

Workaround for Individual Users

In the .profile file, the user can either add the following line to add the needed path:

# dotnet-cli-tools
export PATH=$PATH:~/.dotnet/tools

or, assuming the bad path exists in the PATH, add the following ‘fix-up’ to replace any tildes in the PATH (equivalent to bash):

export PATH=${PATH//\~/$HOME}

The .zprofile may be set to source the .profile file with the following line:

[[ -e ~/.profile ]] && emulate sh -c 'source ~/.profile'

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:10
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
kazo0commented, Jul 22, 2022

Just a bump, I am still experiencing this issue

1reaction
agrosscommented, May 8, 2023

I believe tilde is not expanded in PATH.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot .NET tool usage issues
If you're trying to run a global tool, check that the PATH environment variable on your machine contains the path where you installed...
Read more >
dotnet tool install --global dotnet-ef --version 3.0.0 on MAC ...
Got: Could not execute because the specified command or file was not found. Possible reasons for this include: * You misspelled a built-in ......
Read more >
Cannot debug net6.0-macos Apps - Developer Community
* You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH. It...
Read more >
Network World - Mar 10, 2003 - Google Books Result
PHP, which incidentally is our topic for this week, is also a recursive acronym ... for "PHP: Hypertext Processor" Not quite as clever...
Read more >
MonoGame 3.8.1 - Releases
NET 6 with the latest tools is a must without Visual Studio and Windows. ... macOS dotnet CLI path for global tools is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found