65

When I open my vs code program I get this message: The .NET Core SDK cannot be located. .NET Core debugging will not be enabled. Make sure the .NET Core SDK is installed and is on the path. If I installed and even uninstalled the .NET core SDK and reinstalled it, there were several ways to change the external terminal to Power Shell, but no changes. Another problem I have when I click on the terminal is this message: The terminal shell path "; C: \ Program Files \ dotnet" does not exist

If my .NET is on the same path and persists. Please tell me how can I fix my problem?

Visual studio code : version 1.42.1(x64) .NET core SDK : version 3.1.101(x64)

And I've tried these .NET core SDK versions: version 3.0.100(x64) , version 2.2.207(x64)

elnaz jangi
  • 681
  • 1
  • 6
  • 16

27 Answers27

78
  1. Just simply close your VS Code app. It seems the error is produced because you are installing .NET Core SDK when your VS Code is opened.
  2. After closing it, re-install the .NET Core SDK.
  3. You must be able to use it now.

It worked for me.

Guru Stron
  • 102,774
  • 10
  • 95
  • 132
Bonifacius Sarumpaet
  • 1,263
  • 1
  • 8
  • 21
  • 2
    This worked. Note that re-installing means "Uninstall and Install again" and not "Repair". – halshing Dec 28 '21 at 15:40
  • 2
    Worked for me in 22 Jan 2022. I just did simple Repair in appwiz.cpl and it worked. Note that after restarting VS code you still need to "Kill Terminal" and start "New Terminal". Otherwise u'll still get the same error. Crazy. – wywy Jan 21 '22 at 16:29
  • 1
    This also was my issue. Uninstall the C# extension. Shut everything down and reboot for luck. Open the .NET installer and choose Repair. Reinstall the C# extension. Success. – Stewii Jul 16 '22 at 22:52
  • I also had to reboot – mustafa candan Aug 06 '22 at 12:54
44

I have the 5.0.103 [/snap/dotnet-sdk/112/sdk] installed (as shown, using snap) on KDE neon (based on Ubuntu 20.04).

In order to inform vs code where to find the .Net sdk, set a symbolic link '/usr/local/bin'(this folder is normally in your path):
sudo ln -s /snap/dotnet-sdk/current/dotnet /usr/local/bin/dotnet

After that, restart Visual Studio Code.

This worked for me.

Jean-Marc
  • 740
  • 8
  • 9
  • 2
    Another suggestion for Linux users would be to install .NET some other way than snap because of https://github.com/dotnet/core/issues/4446. For me installing with installation script (https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-install-script) and manually adding symbolic link to /usr/local/bin resolved the error ```ln -s /home/USER/.dotnet/dotnet /usr/local/bin/dotnet``` – Cat-Lord Oct 27 '21 at 17:29
  • 1
    This also worked for me. Seems like a dumb issue when $DOTNET_ROOT is already set. – FailedShack Mar 24 '22 at 17:17
33

I'm on a MAC (High Sierra), and closing VSC and reinstalling SDK did not help in my case.

VSC kept saying that SDK was "not installed or not on the path". When I ran dotnet in the Terminal window I received "command not found" message.

I had to manually add /usr/local/share/dotnet to PATH in my ~/.bash_profile.

Correct path is displayed once SDK is installed (see picture below). I appended it to the PATH in my ~/.bash_profile, reopened Terminal, and it worked. You may have to reload VSC too.

Good luck!

enter image description here

  • 3
    This seem like the perfect solution to me and better than the accepted answer. – Jeff Feb 20 '21 at 18:09
  • 1
    You don't need to uninstall and install again. Just followed this answer and the problem fixed. – Seunghoon Mar 01 '21 at 03:39
  • This helped me get it fixed in Ubuntu. Differences being that in Ubuntu I installed the SDK using snap which puts it in /snap/dotnet-sdk/current. I made a change to ~/.profile to put that folder in my path. – CodeWarrior May 13 '21 at 19:20
  • 1
    In macOs Monterey with an M1, the correct path to add to my ~./bash_profile was: export PATH="/usr/local/share/dotnet/x64:$PATH" It finally worked for me. The other solutions didn't – lextoumbourou Jan 06 '23 at 03:25
22

DON'T DELETE ANYTHING BEFORE TRYING THIS!

To my fellow developers, I find a great and easy method!

1- Open VS Code and go to settings from the bottom left corner! enter image description here

2- Type in @ext:ms-dotnettools.csharp to search dotnet tools! enter image description here

3- Scroll down until you find "Omnisharp: Dotnet Path" and click Edit in settings.json link! enter image description here

4- Go to the end of the file and right before } symbol type in "omnisharp.dotnetPath": "YOUR_DOTNET_LOCATION" enter your dotnet path. note: don't forget to put a comma(,) before your line!

this will show vs code that you have a dotnet installed on your PC! enter image description here

5- We are not done yet! Last but not least go back to settings and find Omnisharp: Use Modern Net Check the box and close your VS code, after reopening you will see that your VS Code detects dotnet! enter image description here

Like this post if it worked out for you!!

One last thing! If your VS code detects it but still no snippets for C# you should check if you've set Omnisharp: Use Global Mono to always, if not then select always to enable it.

Kobi
  • 135,331
  • 41
  • 252
  • 292
Mehmet Ozen
  • 325
  • 4
  • 7
  • 3
    Great fix here. To find your VSCode path on Mac, run `find / -name dotnet` (typically it is `/usr/local/share/dotnet/dotnet`). – fotijr Mar 11 '22 at 21:48
  • @fotijr thats correct! Thanks for mentioning, I don’t know if it does matter but I used my secret folder which is .dotnet, on mac if you use cmd + shift + . You will get to see hidden folders and I used my ‘Users/username/.dotnet’ path in it! I hope default dotnet path also works fine. – Mehmet Ozen Mar 13 '22 at 14:54
9

In my case it helped just to quit VSCode and re-open it (no need to re-install the .NET Core SDK) and the message you mentioned is gone.

AlexxBoro
  • 329
  • 5
  • 3
  • This worked for me as well. I think the path doesn't get updated the first time you open VSCode after installed the .NET Core SDK, or something like that. – xiaodeaux Aug 03 '20 at 20:54
3

Working on Mac M1. I was facing the same issue when I open the project in VSCode. This is how I resolved

Steps:

  1. I quit my VS Code
  2. I reinstalled dotnet SDK
  3. I restarted my project

Initially, when I installed sdk, my VSCode was open, might be that was causing the issue.

Amit Baderia
  • 4,454
  • 3
  • 27
  • 19
2

I have the same problem,but my problem was cause by duplicate installation.

My solution as below:

1、open cmd, check the info of dotnet, I found it was a old version of 6.0.3,but I am sure I have installed a newest version of 7.0

input

dotnet --info

here is the output message

Host (useful for support):
  Version: 6.0.3
  Commit:  c24d9a9c91

.NET SDKs installed:
  No SDKs were found.

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

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

2、check the path of dotnet,I found there is two different path of dotnet

where dotnet

C:\Program Files (x86)\dotnet\dotnet.exe
C:\Program Files\dotnet\dotnet.exe

3、go to the path I found,it’s clear that "C:\Program Files\dotnet" is the correct path of dotnet

C:\Program Files (x86)\dotnet

C:\Program Files\dotnet

4、edit environment variable,delete or move down the wrong path

environment variable

5、restart VScode,this error will not display anymore

hljjj
  • 21
  • 3
1

My issue was I was using .Net version 5 on Apple silicon, when I tried .Net 6 the problem got solved.

1

You can try using homebrew

  1. Install homebrew https://brew.sh
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  1. Close Visual Studio Code
  2. Run brew install --cask dotnet-sdk

If you will have error like this

Error: You have not agreed to the Xcode license. Please resolve this by running:
  sudo xcodebuild -license accept

Then

  1. Run sudo xcodebuild -license accept
  2. Repeat brew install --cask dotnet-sdk
wdr434
  • 41
  • 5
1

I have reinstalled SDK 6 via snap using https://learn.microsoft.com/ru-ru/dotnet/core/install/linux-snap. Then, I have executed a command:

sudo ln -s /snap/dotnet-sdk/current/dotnet /usr/local/bin/dotnet

from https://github.com/dotnet/core/issues/7627

1

quit VS code. quit attached program (unity, etc). open originally attached program. Open VS code (assets > open c# project).

1

For those of you who are on macOS and on M1, and after they closed VS Code and re-installed it, still don't get rid of the error. Try this:

On VS Code, click "Open folder..." and open your user folder. For example my name is Bob and here is the path of my user folder: "Macintosh HD/Users/bob".

Once the user folder is opened, on the left browser panel of VS Code, open those hidden files:

.bash_profile

.zshrc

and at the end of those files, add this:

export PATH="/usr/local/share/dotnet:$PATH"

And save those 2 files.

Basically, it allows apps trying to find .NET SDK to find it in the folder "/usr/local/share/dotnet" which is the default installation folder on macOS Ventura 13.1 (and some previous versions I don't know lol).

To be honest, only one of these two files needs this new line but I'm to lazy to figure out which one.

Restart your Mac and it should work.

Katharsin
  • 101
  • 1
  • 9
1

In my case the issue was that it wasn't installed in WSL. I'm using WSL2 running Ubuntu. So to solve this I just follow these steps on Ubuntu 22.04:

sudo apt-get update && \
  sudo apt-get install -y dotnet-sdk-6.0

If you use other version or want to use dotnet 7.x, follow this howto by Microsoft

1

The problem with my side (using Linux and zsh) is that even after installing the .net and exporting the required paths on ~/.zshrc:

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

The vscode was not being able to find these exports.

So I added the same in my ~/.bash_profile file and Shazam it worked! Looks like sometimes the vscode can not read the zsh files and only the bash ones, so this can be your case.

valdeci
  • 13,962
  • 6
  • 55
  • 80
0

it is not the way to solve this problem but you can do it to have your code run you can open a command on that directory C:\Program Files\dotnet then write this

dotnet run   

and your code will automatically run

Adam Silenko
  • 3,025
  • 1
  • 14
  • 30
0

my solution to this issue is: 1-you must uninstall all of the services belong to Visual Studio(not Vs Code) 2-uninstall VS Code and folder "AppData\Local\Programs\Microsoft VS Code" 3-download new dotnet core SDK and install vs code I hope it's done for you

Rebwar
  • 413
  • 3
  • 17
  • 2
    This sounds like a bit of a nuisance; anyone reading this should check the upvoted answer below first as it seems to work for quite a few people. – PeterT Jul 19 '21 at 10:59
  • https://stackoverflow.com/a/62748238/5013141 This answer is working for people – Michael Fulton Jul 27 '21 at 19:31
0

I downloaded the Build tools for Visual Studios 2019 and that seemed to fix my issue on VS Code.

So go to this URL: https://visualstudio.microsoft.com/downloads/

All Downloads -> Tools for Visual Studio 2019 -> Build Tools for Visual Studio 2019

Then of course, download and run, then select "C++ Build tools" and ".NET desktop build tools" and install.

Worked for me, hopefully works for others too.

Henry H.
  • 21
  • 3
0

The same issue happened to me when I installed an extension. The reason was I didn't have .NET Core SDK installed. What I did to get rid of the issue was:

  1. Close VS Code
  2. Install .NET Core SDK
  3. Re-install the extension (in my case)
Dharman
  • 30,962
  • 25
  • 85
  • 135
Barmatch
  • 31
  • 1
0

Start VSCode from your terminal:

code pathToProject

For MacOS, Linux and Windows users alike.

From the Troubleshooting: 'The .NET Core SDK cannot be located.' errors wiki page in OmniSharp's VSCode repo:

If which dotnet produces a PATH, then the .NET SDK was able to successfully modify the PATH, but VS Code isn't picking it up. VS Code attempts to scrape the environment by launching the default shell under the covers. But this process can be fragile. You can attempt to work around this by starting VS Code from your Terminal.

Johnny Bueti
  • 637
  • 1
  • 8
  • 27
0

Basically my goal was to get dotnet commands working on terminal on VS code. For that I spent an hour or two trying to find a solution. I came across a command "dotnet new console", and If i can execute it in the terminal of VS code I can get it to work. But it doesn't because it couldn't identify what dotnet was in the first place. The dotnet commands only worked on my base/usual cmd that comes with windows OS. So what I did was open my file in windows explorer that gives the error, open terminal in the same folder the project file is in (basically the folder that just popped up), and ran the script ("dotnet new console") without the quotes or brackets. It worked and I could use dotnet commands in the terminal of VS Code.

I have shown some arrows indicating files that weren't there before I ran the command. These files were added after running dotnet new console

enter image description here

0

Changing System Environment Variable Path from C:\Program Files (x86)\dotnet to C:\Program Files\dotnet fixed the problem for me.

D J
  • 845
  • 1
  • 13
  • 27
Leandro
  • 115
  • 5
0

If you are on Mac M1, make sure the package is ARM64. You choose if you want x64 or ARM64 when you download at the page, https://dotnet.microsoft.com/en-us/download/dotnet

This worked for me.

I also added the path to my .bash_profile file

You can find the .bash_profile file in your finder once you allow the showcase of hidden files.

alfredo-fredo
  • 652
  • 7
  • 7
0

I was having the same issue and tried answers here but they didn't solve the issue.

Finally I solved this by opening the project folder from terminal with code . as dotnet says here

I am using Unity and was opening the project folder by double-clicking the C# file on Unity. That was the issue in my case.

Hope this helps :)

Masa
  • 362
  • 2
  • 14
0

uninstalling and then

sudo snap install dotnet-sdk --classic --channel=7.0

worked for me.

persona
  • 70
  • 7
-1

This for future:- hi Jeeva if you install again unity with vscode please read this

First install vscode extension https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp

If you got error like this "The .NET Core SDK cannot be located. .NET Core debugging will not be enabled. Make sure the .NET Core SDK is installed and is on the path" then install https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/sdk-6.0.300-windows-x64-installer

If vscode shows "The reference assemblies for .NETFramework,Version=v4.7.1 were not found" on output terminal then install developer pack https://dotnet.microsoft.com/en-us/download/dotnet-framework/net471 then try exit and open vs code if not work then restart

Jeeva
  • 1,707
  • 1
  • 10
  • 7
-2

If you absolutely cannot get .NET Core SDK installed so that Omnisharp can find it, try unchecking the checkbox next to "Show Omnisharp Log On Error" under Settings > Extensions > C# Configuration > [] Show Omnisharp Log On Error

William
  • 491
  • 5
  • 9
-8
  • Click on the error that is shown on your VS Code
  • Get into Settings of the error
  • Download it and you are all set

As shown in the image

Peter Csala
  • 17,736
  • 16
  • 35
  • 75