Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jsoref opened this issue Oct 20, 2021 · 8 comments
Milestone

Comments

@jsoref
Copy link

jsoref commented Oct 20, 2021

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:

?? @"/etc/paths.d/dotnet-cli-tools";
public OsxBashEnvironmentPath(
BashPathUnderHomeDirectory executablePath,
IReporter reporter,
IEnvironmentProvider environmentProvider,
IFile fileSystem
)
{
_packageExecutablePath = executablePath;
_fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
_environmentProvider
= environmentProvider ?? throw new ArgumentNullException(nameof(environmentProvider));
_reporter
= reporter ?? throw new ArgumentNullException(nameof(reporter));
}
public void AddPackageExecutablePathToUserPath()
{
if (PackageExecutablePathExists())
{
return;
}
_fileSystem.WriteAllText(DotnetCliToolsPathsDPath, _packageExecutablePath.PathWithTilde);
}
private bool PackageExecutablePathExists()
{
var value = _environmentProvider.GetEnvironmentVariable(PathName);
if (value == null)
{
return false;
}
return value
.Split(':')
.Any(p => p == _packageExecutablePath.Path || p == _packageExecutablePath.PathWithTilde);
}
public void PrintAddPathInstructionIfPathDoesNotExist()
{
if (!PackageExecutablePathExists())
{
if (_fileSystem.Exists(DotnetCliToolsPathsDPath))
{
_reporter.WriteLine(
CommonLocalizableStrings.EnvironmentPathOSXNeedReopen);
}
else
{
// similar to https://code.visualstudio.com/docs/setup/mac
_reporter.WriteLine(
string.Format(
CommonLocalizableStrings.EnvironmentPathOSXBashManualInstructions,
_packageExecutablePath.Path));

Homebrew/homebrew-cask#112988

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Tools untriaged Request triage from a team member labels Oct 20, 2021
@marcpopMSFT marcpopMSFT self-assigned this Oct 25, 2021
@marcpopMSFT marcpopMSFT assigned dleeapho and unassigned marcpopMSFT Oct 25, 2021
@dleeapho
Copy link

@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
Copy link
Member

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

@jsoref
Copy link
Author

jsoref commented Oct 27, 2021

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
Copy link

dleeapho commented Nov 5, 2021

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
Copy link

sshquack commented Nov 14, 2021

@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
#22588
#9415
#13308
#10177
#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
Copy link
Author

jsoref commented Nov 14, 2021

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

@marcpopMSFT marcpopMSFT assigned dsplaisted and unassigned dleeapho Dec 13, 2021
@jrdodds
Copy link

jrdodds commented Dec 23, 2021

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

@tony-sol
Copy link

tony-sol commented Jun 6, 2023

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

@JL03-Yue JL03-Yue added this to the 9.0.1xx milestone Apr 4, 2024
@JL03-Yue JL03-Yue removed the untriaged Request triage from a team member label Apr 4, 2024
@JL03-Yue JL03-Yue removed their assignment Apr 19, 2024
@marcpopMSFT marcpopMSFT modified the milestones: 9.0.1xx, Backlog Aug 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants