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

[BUG] Failed to find dotnet from path with "which dotnet" #1565

Closed
dibarbet opened this issue Oct 28, 2024 · 17 comments
Closed

[BUG] Failed to find dotnet from path with "which dotnet" #1565

dibarbet opened this issue Oct 28, 2024 · 17 comments

Comments

@dibarbet
Copy link
Member

Describe the Issue

Originally filed by @avatar-lavventura at dotnet/vscode-csharp#7701

I have installed dotnet sdk inside MacBook and in my terminal dotnet --info returns valid information.

But inside Visual Studio Code, I am getting following error message, when I try to run the project:

Failed to find dotnet from path with "which dotnet".
Cannot find .NET SDK installation from PATH environment. C# DevKit extension would not work without a proper installation of the .NET SDK accessible through PATH environment. Rebooting might be necessary in some cases. Check the PATH environment logged in the C# DevKit logging window. In some cases, it could be affected how VS code was started.
PATH=/usr/bin:/bin:/usr/sbin:/sbin

How can I fix this error? Note that vscode tries to read PATH from /bin/sh rather than /bin/bash.

Steps To Reproduce

No response

Expected Behavior

No response

Environment Information

No response

@avatar-lavventura
Copy link

avatar-lavventura commented Oct 29, 2024

Thank you @dibarbet

The solution I have tried from https://stackoverflow.com/a/79131320/2402577:

Confirm that the path to your .NET SDK is included in your PATH. Or on your VSCode settings.json you can setup it:

"terminal.integrated.env.osx": {
   "PATH": "/usr/local/share/dotnet:/usr/bin:/bin:/usr/sbin:/sbin"
 }

An altdernative is change for bash to zsh or your default shell,

"terminal.integrated.defaultProfile.osx": "zsh"   // Or "bash" if you use Bash

But I am still having the same error. Looks like settings.json is not considered or something is overwriting onto it.

@arunchndr
Copy link
Member

@nagilson would you first scout? Also, is this something we will have covered in the PATH api switch?

@nagilson
Copy link
Member

The PATH API considers both bin/sh and bin/bash. Although it's not supporting SDK lookup initially, if we added it based on our current plans post our recent conversation on Friday, I would expect it to work here.

@nagilson
Copy link
Member

Sometimes vscode does not load the environment properly, but that may be based on the users settings. If the user sets the PATH in both bin/bash and bin/sh, then launching vscode through the terminal, Im curious to see if it works? Im also curious if it works if they set DOTNET_ROOT.

@avatar-lavventura
Copy link

@nagilson I confirm that PATH in /bin/bash is set. /bin/sh reads from .profile I assume, that is set as well. Like /bin/sh in terminal see my PATH where /bin/sh in vscode does not.

@dibarbet
Copy link
Member Author

dibarbet commented Oct 29, 2024

Maybe dumb question - have you fully restarted VSCode? Not just closing the window but in the top left bar quit the entire application? IIRC there was an issue on Mac where changes to PATH or other environment variables wouldn't be seen until VSCode was quite entirely.

@avatar-lavventura
Copy link

@dibarbet Yes sir I have restarted the VSCode, restarted to computer as well. /bin/sh in vscode only sees /usr/bin:/bin:/usr/sbin:/sbin and does not see /usr/local/share/dotnet//dotnet :-(

I was not able to figure out how can I update its PATH (seems like its the only solution) or somehow force vscode to use /bin/bash.

@nagilson
Copy link
Member

@avatar-lavventura Thank you for responding to us.
Can you try this please? Within the vscode terminal:

node (You may need node.js to be installed, if its not installed I'd recommend node 20, to enter the node terminal)
require('child_process').spawnSync('env', [''], { env : process.env, shell : '/bin/sh/' }).stdout.toString()
require('child_process').spawnSync('env', [''], { env : process.env, shell : '/bin/bash/' }).stdout.toString()

And share the result of the PATH from that output (denote privacy)

@avatar-lavventura
Copy link

I am getting following error:

❯ node
Welcome to Node.js v20.9.0.
Type ".help" for more information.
> require('child_process').spawnSync('env', [''], { env : process.env, shell : '/bin/sh/' }).stdout.toString()
Uncaught TypeError: Cannot read properties of null (reading 'toString')
> require('child_process').spawnSync('env', [''], { env : process.env, shell : '/bin/bash/' }).stdout.toString()
Uncaught TypeError: Cannot read properties of null (reading 'toString')

@nagilson
Copy link
Member

Thank you. I am sorry but there wasn't supposed to be a / at the end 🤦
require('child_process').spawnSync('env', [''], { env : process.env, shell : '/bin/sh' }).stdout.toString()
require('child_process').spawnSync('env', [''], { env : process.env, shell : '/bin/bash/' }).stdout.toString()
This seems to work for me.
Image

@avatar-lavventura
Copy link

For both command I get following for PATH and terimal in vscode is able to see dotnot process:

  'PATH=/usr/local/share/dotnet/:/Users/alper/.pyenv/shims:/usr/local/Cellar/pyenv-virtualenv/1.2.4/shims:/usr/local/opt/make/libexec/gnubin:/usr/local/opt/imagemagick@6/bin:/usr/local/opt/curl/bin:/Users/alper/.npm-packages/bin:/usr/local/opt/coreutils/libexec/gnubin:/usr/local/opt/ruby/bin:/usr/local/lib/ruby/gems/3.0.0/bin:/Users/alper/venv/bin:/usr/local/sbin:/usr/local/lib/node_modules/bin:/usr/local/bin:/Users/alper/.cargo/bin:/Users/alper/venv/bin:/Users/alper/.local/bin/:/Users/alper/Downloads/camino/bin:/usr/local/opt/grep/libexec/gnubin:/Users/alper/bin/:/Users/alper/personalize/bin:/Users/alper/ebloc-broker/broker/eblocbroker:/Users/alper/ebloc-broker/broker/bash_scripts:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/bin:/Applications/VMware Fusion.app/Contents/Public:/Library/TeX/texbin:/Applications/Little Snitch.app/Contents/Components:/usr/local/share/dotnet:/opt/X11/bin:~/.dotnet/tools:/Users/alper/.cargo/bin:/snap/go/current/bin:/Users/alper/go/bin:/Users/alper/.gem/bin:/opt/ss:/usr/local/Cellar/ruby/3.2.2/bin:/Users/alper/.local/bin:/Users/alper/.local:/usr/local/opt/fzf/bin:/Users/alper/.local\n'

@nagilson
Copy link
Member

nagilson commented Nov 4, 2024

Thank you. That's the code that our new API does use to scan the PATH, so this increases my confidence that the change we are working on would fix this scenario. And interesting to see that node is working fine here. If it doesn't get fixed by our change then honestly I (us at MSFT) would take this to vscode and talk to them to see why is invoking this code in their context not getting the same result

@avatar-lavventura
Copy link

Thank you sir. When would be the change will take the place? How can I update it?

@nagilson
Copy link
Member

nagilson commented Nov 4, 2024

Some parts still need to be implemented. Youd get the update automatically as long as you havent disabled automatic extension updates. But I imagine it will still be a few weeks out. In the meantime, I would try setting DOTNET_ROOT in your terminal and launching vscode from there to see if it helps. Otherwise, the OP would be the one who could provide a workaround.

@webreidi webreidi modified the milestones: Oct2024, Nov2024 Nov 13, 2024
@webreidi webreidi modified the milestones: Nov2024, Dec2024 Dec 6, 2024
@webreidi
Copy link

@nagilson any update on this? Should this be moved forward another milestone as we wait for all the parts to use the new API?

@nagilson
Copy link
Member

For C# it's in prerelease and for DevKit it's in a PR thats about to be merged. Any work on my teams end is pretty much complete besides maybe caching. It wont be turned on by default for DevKit though. I would move it forward if you'd like to make a new thing to track turning it on by default.

@nagilson
Copy link
Member

The latest pre-release version of C# Dev Kit extension (1.16.4) has a new implementation for locating dotnet which should fix this.

To do that, you need to uncheck this setting located under Extensions -> C# -> C# Dev Kit: Dotnet: Use Legacy Dotnet Resolution.

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

No branches or pull requests

5 participants