dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.69k stars 1.06k forks source link

dotnet-sdk installs bogus `~/.dotnet/tools` entry as `/etc/paths.d/dotnet-cli-tools` #22214

Open jsoref opened 2 years ago

jsoref commented 2 years ago

We installed dotnet-sdk using brew today and the /etc/paths.d/dotnet-cli-tools it created injected a bogus ~ into the system PATH variable which results in kubectl getting upset.

The /etc/paths.d directory (managed by /usr/libexec/path_helper) takes static files and literally inlines their contents into a produced PATH env string.

This PATH env string is not later evaluated, which means that a ~ in a file in /etc/paths.d, as in: /etc/paths.d/dotnet-cli-tools:

~/.dotnet/tools

Will not get converted into the equivalent of $HOME/.dot/tools.

This gets reported by victims in issues such as kubernetes/kubectl#574.

I think that this is caused by: https://github.com/dotnet/sdk/blob/a30e465a2e2ea4e2550f319a2dc088daaafe5649/src/Cli/dotnet/ShellShim/OsxBashEnvironmentPath.cs#L23-L78

https://github.com/Homebrew/homebrew-cask/issues/112988

dleeapho commented 2 years ago

@marcpopMSFT this issue is about the casked brew installer, ie the brew installer does whatever the MS pkg installer does. This issue belongs in dotnet/installer I believe. (The non-cask brew installer is the source-built one.)

marcpopMSFT commented 2 years ago

@dleeapho are you saying that this would repro with our MS pkg as well? I know nothing about casked brew.

jsoref commented 2 years ago

Brew just downloads a package from here and asks the installer to run it.

https://github.com/Homebrew/homebrew-cask/blob/master/Casks/dotnet-sdk.rb#L5

dleeapho commented 2 years ago

are you saying that this would repro with our MS pkg as well?

I think trying to repro with the MS pkg would be a good start. I'm no expert on Casks either so I cannot discount Cask interaction though my understanding is as @jsoref stated.

sshquack commented 2 years ago

@dleeapho are you saying that this would repro with our MS pkg as well? I know nothing about casked brew.

@marcpopMSFT I am able to reproduce this issue on a vanilla macOS 12 and vs for mac 2019 8.10.13.2 pkg installer (no brew cask involved) directly from https://visualstudio.microsoft.com/vs/mac/ The installer is adding ~/.dotnet/tools to $PATH which won't expanded the ~ automatically. The current workaround is for every VS for mac dotnet developer to add export PATH=$HOME/.dotnet/tools:$PATH manually in their .rc or .profile shells to invoke a global tool.

All the following issues are related to the ~ not being expanded in PATH https://github.com/dotnet/sdk/issues/22588 https://github.com/dotnet/sdk/issues/9415 https://github.com/dotnet/sdk/issues/13308 https://github.com/dotnet/sdk/issues/10177 https://github.com/dotnet/sdk/issues/2998

I don't fully know what the right solution here is but this is leading to a poor developer experience because every new developer trying to install critical tools like (dotnet-ef, dotnet-format, etc) will have to do an unnecessary manual workaround that the pkg installer should have done in the first place.

jsoref commented 2 years ago

I'd half argue in favor of adding a /usr/local/bin/.dotnet-tools instead and making that a symlink to $HOME/.dotnet/tools.

jrdodds commented 2 years ago

I have reproduced the issue with the Microsoft installer package from https://dotnet.microsoft.com/en-us/download.

tony-sol commented 1 year ago

Please, add env variable to define path to tools! It's all kind a mess with different paths of tools, datas, etc. - best way is make dotnet follow XDG spec in all platforms according to this or similar