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

The .NET Core SDK cannot be located #3401

Closed
GhostShot3 opened this issue Nov 10, 2019 · 28 comments
Closed

The .NET Core SDK cannot be located #3401

GhostShot3 opened this issue Nov 10, 2019 · 28 comments

Comments

@GhostShot3
Copy link

GhostShot3 commented Nov 10, 2019

Environment data

dotnet --info output:
It was not possible to find any installed .NET Core SDKs
Did you mean to run .NET Core SDK commands? Install a .NET Core SDK from:
https://aka.ms/dotnet-download

Host (useful for support):
Version: 3.0.0
Commit: 95a0a61858

.NET Core SDKs installed:
No SDKs were found.

.NET Core runtimes installed:
Microsoft.NETCore.App 3.0.0 [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files (x86)\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download

VS Code version:
1.40

C# Extension version:
1.21.6

Steps to reproduce

Expected behavior

VScode find .net core sdk

Actual behavior

VScode can't find .net core sdk but i installed it
11

@GhostShot3 GhostShot3 changed the title The .net Core SDK cannot be located The .NET Core SDK cannot be located Nov 10, 2019
@OhSoooLucky
Copy link

Same thing when using 1.21.7

@OhSoooLucky
Copy link

The net core 3.0-rc1 sdk works perfectly fine: https://dotnet.microsoft.com/download/thank-you/dotnet-sdk-3.0.100-rc1-windows-x64-installer

@GhostShot3
Copy link
Author

Failed to install

@gregg-miskelly
Copy link
Contributor

Please, don't install the 3.0-rc1 SDK -- that is an outdated release candidate.

@GhostShot3 the output you have from above indicates that the C# extension is working correctly - you don't have a .NET SDK installed, just a .NET runtime. Did you install an SDK? Here is the current install link from https://dotnet.microsoft.com/learn/dotnet/hello-world-tutorial/install

@GhostShot3
Copy link
Author

Yes i install i tryed and say already installed

@gregg-miskelly
Copy link
Contributor

Can you try uninstalling it and reinstalling it? I suspect something went wrong with the first install.

@GhostShot3
Copy link
Author

Worked, thank you

@nightblade9
Copy link

Just wanted to chime in and say I saw the same problem, with the same resolution.

In my case, I uninstalled several things (.NET Core 2.2.7, .NET Core 3.0, NuGet, Mono) and reinstalled just the .NET Core 3.0. That seemed to resolve the problem.

It looks like VSCode was picking up the MSBuild/etc. from the Mono folder (mine was Mono 6.0 for some reason), but anyway, reinstall for the win.

(I'm on Linux if that matters)

@MikaelElkiaer
Copy link

MikaelElkiaer commented Dec 17, 2019

I have this problem when starting VSCodium with drun.
Starting VSCodium from zsh and it works as expected.

Can anyone explain what the different in these two methods could be? Something related to paths I imagine.

Update: Actually, I do get what I expected from dotnet --info when running that in a terminal.
And if I have one instance of VSCodium open that I started from terminal. Any extra instances I open with drun now works.

Update 2: It was strictly a VSCodium issue, works fine in VSCode.

@newVincentFong
Copy link

Environment

  • .NET Core SDK 3.1
  • VSCode C# Extension 1.21.9
  • Mac

Reference

OmniSharp/omnisharp-vscode Wiki

If you had Visual Studio Code open at the time you installed the .NET SDK, and you haven't restarted it, you should do so.

My Solution

Exit VSCode and open it...

Reason

I try not to exit vscode on my mac when it's connected to a monitor because vscode has some
GPU rendering problem in this circumstances. This habbit leads to the problems.

@JoeRobich
Copy link
Member

Also note, if you are installing .net sdk on a platform where we do not provide an installer or where you want to automate the installation. The dotnet-install script should configure everything necessary. https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-install-script

@JackTiber
Copy link

This issue pops up on Ubuntu 20.04 following both links above, when installing using APT, snap or the script cited. I can run which dotnet and verify the sdk binary is in PATH, but when opening vs code from the same terminal session using code . it still throws the errors around the missing SDK.

@gregg-miskelly
Copy link
Contributor

@JackTiber In case you haven't already read this: https://github.com/OmniSharp/omnisharp-vscode/wiki/Troubleshooting:-'The-.NET-Core-SDK-cannot-be-located.'-errors

This issue isn't a problem with this extension -- this is either a problem with VS Code, or with your shell. There is instructions in there on debugging VS Code if you are so inclined.

@JackTiber
Copy link

@gregg-miskelly thanks for the link! So oddly, that did help with VS Code popup regarding a missing SDK, but then in the actual output logs of the Omnisharp plugin's language server, it still fails to find an SDK binary to use. Originally, I had the sdk installed via APT, but most recently used SNAP to see if that worked.

At this point, I am going to do a full wipe of the machine and start from scratch, to also support a couple of hardware updates I am making. Will check back in either way, but definitely a lot of issues installing it on LTS versions of Ubuntu.

@Cabola
Copy link

Cabola commented Jun 2, 2020

If there's still people having this issue then try this:

  1. From start menu search for "this pc", right click and select properties.
  2. Click Advanced system settings
  3. Click on "Environment Variables..."
  4. Select either the Users or Systems "Path" variable and click Edit...
  5. In either of them you should find the path to your "dotnet" folder

now in my case I had 2 C:\Program Files (x86)\dotnet\ and C:\Program Files\dotnet\ if you actually go to the folders you'll notice that there's no sdk folder within the C:\Program Files (x86)\dotnet\ folder. So simply select C:\Program Files\dotnet\ and click the "move up" button. Then click OK all the way out of there, now try and see if things are working..

@visuallization
Copy link

I basically just had to restart my pc after installing the .NET sdk. Then it all worked! I guess some changes (env variables?) needed a reboot.

@Drexlin
Copy link

Drexlin commented Sep 17, 2020

@JackTiber Where you able to solve your issue? I'm having the same problem and wondering if going nuclear is my only option at this point. Thanks.

@JackTiber
Copy link

@Drexlin I did. At the end of the day, the best method I found was to remove any trace of the SDK (snap especially which can have even more issues than installing via APT in the docs) and then re-installing using APT. Once it is installed, verify that you can get the binary on your path with which dotnet, but do not try to use it yet. Restart your machine, which I recommend actually shutting down completely and then bringing it back up. At that point, it started working for me.

The link @gregg-miskelly provided is pretty helpful in detailing the troubleshooting steps.

Honestly, if I had to guess this probably has something to do with where the binary is installed on Debian based systems and the spawned shell for the extension / VS Code, which is somehow why the restart makes a difference. Some environment variable that isn't set after installation is probably set during startup and fixes the issue. Recently worked with a Fedora 32 machine and had all of 0 problems getting the SDK installed and working with the extension and code.

@Drexlin
Copy link

Drexlin commented Sep 18, 2020

@JackTiber Thanks, I will try that. If I can't get it to work, maybe I'll give CentOS a try.

@Gerhard-Piette
Copy link

Gerhard-Piette commented Sep 25, 2020

@Drexlin @JackTiber @gregg-miskelly

I made this post already here and here.

DO NOT USE Ubuntu.
Not even the Binary file from https://dotnet.microsoft.com/download/dotnet/5.0 works because the dotnet executable is not recognized on Ubuntu. I guess it is related to dotnet-sdk on snap on Ubuntu.

I have no problems using the .net5 RC1 on Fedora 33 beta.

Download the dotnet-sdk SDK manually.
I have downloaded the Binaries from https://dotnet.microsoft.com/download/dotnet/5.0
No package manager.

Start VSCode with a script file with this content:
export PATH=$PATH:/YYY/
/home/XXX/Downloads/VSCode/code-insiders

where you have to adapt XXX and YYY to your case.
YYY is the folder where you have stored the SDK.

DO NOT USE Ubuntu snap.
Someone working on snap dotnet-sdk must have introduced an automatic "dotnet" alias that is listed but can not be removed with the "sudo snap unalias dotnet" command because Error: "cannot find manual alias "dotnet" in any snap".
Unfortunately the people working on omnisharp do not care about this problem.

From my console:

xxx:~$ dotnet

Usage: dotnet [options]
Usage: dotnet [path-to-application]

Options:
-h|--help Display help.
--info Display .NET information.
--list-sdks Display the installed SDKs.
--list-runtimes Display the installed runtimes.

path-to-application:
The path to an application .dll file to execute.
xxx:$ snap aliases
Befehl Alias Anmerkungen
dotnet-sdk.dotnet dotnet -
xxx:
$ sudo snap unalias dotnet
Fehler: cannot find manual alias "dotnet" in any snap

Previously:

I made this post already here and here.

On Ubuntu 20.04.1, the problem is the snap alias. Do not install it.

Instead do this:

sudo snap install dotnet-sdk --channel=5.0/beta --classic

DO NOT install the alias because it makes Omnisharp not find the SDK.
sudo snap alias dotnet-sdk.dotnet dotnet

It can be removed with:
sudo snap unalias dotnet

Start VSCode with a script file with this content:
export PATH=$PATH:/snap/dotnet-sdk/current/
/home/XXX/Downloads/VSCode/code-insiders

You have to adapt the second line, that starts VSCode insiders, to your case.

@sophin123
Copy link

I was having the same problem. I changed the path of dotnet from the environment variables. After that, i restart the visual studio it works,
To do that,
Open My Computer
Right Click and go to properties
Go to Advanced System Properties
Go to Environment Variables
Find the path and select edit
Add new path if not exist,
C:\Program FIles\dotnet
If it's already their, then it might be other problems.

@radiantone
Copy link

On linux, I have dotnet in my path and in common path /usr/bin/dotnet and the extension cannot find it.

@mayconvs
Copy link

Cara, uso Windows... No meu, lá nas Variáveis de Ambiente, por algum motivo estava vindo um ";" no inicio do diretório do dotnet... Retirei, reiniciei o Visual S. C. e funcionou.

@ozgurtezel89
Copy link

ozgurtezel89 commented Jul 9, 2021

I had to uninstall the dotnet-sdk (5.0), which I had previously installed via snap
Then I have installed it again with the below command, and it worked for me.
my system is Ubuntu 20.04

  sudo apt-get update; \
  sudo apt-get install -y apt-transport-https && \
  sudo apt-get update && \
  sudo apt-get install -y dotnet-sdk-5.0

@random-pixels
Copy link

This morning my VSCode updated (on Linux Mint 21). When it updated, several packages were updated also including the SDK. (I am using apt, not snap). After opening VSCode, the command dotnet build no longer works. I see an error that there is no SDK installed. dotnet --info confirms that it doesn't think there is an SDK. I uninstalled and reinstalled the dotnet-sdk-6.0 package, restarted my computer, but still get the error. The link provided above did not offer any solutions. It worked fine yesterday before the update. I now have 1.70.1, released yesterday. Starting from command line or menu makes no difference.

How do I get VSCode to recognize the SDK? Or, if I have to, roll back the update?

@irvanherz
Copy link

For me, in linux system, moving these variables from .bashrc to /etc/profile can solve the problem.

export DOTNET_ROOT=$HOME/.dotnet
export PATH=$PATH:$HOME/.dotnet:$HOME/.dotnet/tools

It looks like vscode doesn't load variables from .bashrc

@mikeyjoel
Copy link

mikeyjoel commented Jan 31, 2024

Installation
For anyone running into issues, do the following method, which will work on all distributions and has been tested with automation/provisioning tools:

If you run into issues, please check your distro's required dependencies here:
https://learn.microsoft.com/en-us/dotnet/core/install/linux-scripted-manual#dependencies
https://github.com/dotnet/core/blob/main/release-notes/8.0/linux-packages.md

sh -c "$(curl -fsSL https://dot.net/v1/dotnet-install.sh)"
Follow the prompts until the installation is complete. This will be installed on your home path.

or

Just download and extract to ~/.dotnet from https://dotnet.microsoft.com/en-us/download/dotnet/8.0

Now, vscode needs to be able to find just the dotnet binary at /usr/share/dotnet else you will get an error.

Let's go ahead and create a soft link

sudo ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet

Optionally copy the directory to the /usr/share/dotnet path for multi-user support when provisioning.

sudo mkdir -p /usr/share/dotnet
sudo cp -R ~/.dotnet/* /usr/share/dotnet/
sudo chown -R root:root /usr/share/dotnet

You will want to create the export regardless, especially the tools path, since you'll want to install some nugpkgs.

You can create your dotnet alias and tools export on either ~/.bashrc or ~/.zshrc (Yes, an alias, since the soft link will always assume priority, and you will have workload installs going to the root user instead of your own user - among other nupkg breaks and repairs)
code ~/.zshrc
Append the following two lines

export DOTNET_ROOT=$HOME/.dotnet
export PATH=$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools

Finally, save the file and source it so you don't have to logout/reboot
source ~/.zshrc

Optionally append the following exports for multi-user provisioning at /etc/profile.local (don't edit /etc/profile - changes will be lost after updates/upgrades). Reboot once done for the changes to take effect.

export DOTNET_ROOT=/usr/share/dotnet/
export PATH=$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools

.Net Uninstall Tool
If you are like me and have to manage various versions of .Net, you will want to have the uninstall tool, making it easier to manage versions not wanted in the future.

https://github.com/dotnet/cli-lab/releases

Testing!
You can use one of the guides provided to create a new project and ensure you don't get any errors with dependencies or other issues.

I 100% recommend test-driving it with the following two quick projects:

https://dotnet.microsoft.com/en-us/learn/dotnet/hello-world-tutorial/intro
https://dotnet.microsoft.com/en-us/learn/aspnet/blazor-tutorial/intro

BONUS: Testing with the OpenSource MonoGame Framework! (A Microsoft XNA Fork)
Personally, I needed to publish a game ASAP and ran into this horrible issue.
Here is another quick project you can use to test using the monogame framework:

dotnet new --install MonoGame.Templates.CSharp
mkdir -p ~/csharp_projects
dotnet new mgdesktopgl -o ~/csharp_projects/monogamedev

Up to this point, you should be able to launch the asset/content builder mgcb-editor just for testing purposes from inside the root of the project folder we just created:

cd ~/csharp_projects/monogamedev
dotnet mgcb-editor

Now, let's pretend we are publishing:
dotnet publish -c Release -r linux-x64 /p:PublishReadyToRun=false /p:TieredCompilation=false --self-contained

Launch the game
~/csharp_projects/monogamedev/bin/Release/net6.0/linux-x64/publish/monogamedev

You should get an empty game canvas from the monogame framework running.

If your project or environment gets messed up at any point, restore it.
dotnet restore

Reference: https://monogame.net/articles/getting_started/1_setting_up_your_development_environment_unix/

Happy Coding! and/or Automated provisioning!

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

No branches or pull requests