the .NET SDK is not showing up unless run from the folder - c#

I've been trying to set up .NET on my Windows 10 computer. I downloaded the latest SDK and I ran the installer, and it was succesful. However, whenever I run dotnet --version in command prompt or powershell, it says it can't find any version of it. However, when I ran the command after launching it from file explorer(typing cmd at the top where the file path is), it gave me the correct version(latest). I tried adding it to the path as well, still nothing. I also tried uninstall reinstall and a repaire, nothing works. I'm trying to learn the C family and I'm starting with C#, however I can't execute my codes through visual studio code or command prompt. What should I do?

https://dotnet.microsoft.com/learn/dotnet/hello-world-tutorial/intro
Quickstart for .Net - core app.

To answer my own question, I somehow had a corrupt entry, and instead of trying to just repair it with the installer, I had to uninstall(yes I'm stupid I forgot to do this before), and reinstalled it. It now works perfectly.
So I did this again on my laptop, had a different problem though. It seems that I had multiple installations of dotnet, one a 32 bit and one 64 bit.
Ran this to check if there were multiple installed:
where dotnet
I then deleted both of them, and reinstalled and presto!

Related

Unable to run a MonoGame project on a clean installation of Visual Studio and MonoGame

I recently got a new computer, and finally got around to installing MonoGame, as I worked with it a few months back on my old computer, and primarily use Unity for my game development when not working on 2D games. Their website says they have CLI templates that work with Rider, but I figured it would be best to get it installed with Visual Studio first. Following the exact steps listed on the MonoGame website, I got everything installed that I needed, and started a project from one of the Visual Studio MonoGame templates. Upon opening the project, and everything finishing loading, I am greeted to this miserable sight. I also had an error in the console relating to MonoGame, with the error code MSB3073. From what research I did, I found that it either had to do with my username having a space in it (it clearly does not, so that was out of the picture), or it had to do with using the Visual Studio templates, and I would simply need to create the project from the CLI templates, as seen here. However, creating a new project from the CLI templates does not change anything. I have tried uninstalling and reinstalling dotnet, I have tried uninstalling and reinstalling Visual Studio. I have, of course, powered my computer off and back on multiple times. Even trying to open the project in Rider after installing the proper MonoGame packages in the program has the same exact errors. But when I zipped the project up and sent it to a friend who works with MonoGame, he was able to run the project with no issues, so clearly it has something to do with my setup.
I have also cleaned my nuget cache, cleared my project temp folders, and cleared the visual studio cache. Eventually, the Microsoft dependencies stop having issues when I simply close and open the project again, but every time I open the project in Visual Studio, I get the same error in the console, and it prevents me from running/building the project.
Hoping someone on here will know what to do with the info I've given, as I'm completely out of ideas!
So I figured it out. I'm not very experienced with the command line, but I managed to find a very nice tutorial by someone who wanted to make games with MonoGame using only the command line. In it, I was able to attempt to build the project from the CLI, and it gave me an error message unlike what was in Visual Studio. It said that MonoGame only works on a 64bit OS, but I'm on a 64bit OS. So I went to look at what version of dotnet was being used, and sure enough, it was the 32 bit version! It took a while to figure out how to uninstall it, and how to use the dotnet-core-uninstaller tool in the command line. Then all I had to do was remove the Environment Variable in the System category for the Path variable that referenced the Program Files (x86) directory of dotnet.
Hopefully if anybody else comes across this issue, they'll find this post, as none of the others seemed to fully explain how to do anything that needed to be done to fix the problem :)

.NET SDK's Not Installing Correctly

I am getting an issue with installing the .NET SDK, at first when I went into visual studio 2019 it said that I was missing the dotnet runtime sdk so I installed it like it asked and restarted my computer. I then went on to visual studio 2019 again, and the same issue arose, I went into my command prompt and typed dotnet --list-sdks and it displayed no sdks. I have all of the runtimes installed, but it says No SDKs were found. image . I tried re-installing the sdks but the same problem stuck. I even went as far as to re-install IIS. I can't do anything without this being fixed please help soon!
Before you try a manual install, I'd check if the Path in the system's environment variables is correctly configured for your system.
Given that there's always one shared host that moves forward, it will either pick the x86 or the x64 version on your machine. This issue of not picking the right one might happen if you install multiple/different versions.
Run the where.exe dotnet command to see where the host is looking for the SDK (it's the first entry returned). If you're on a x64 machine, you want to have C:\Program Files\dotnet listed first.
If it's not, edit the Path system's environment variable to have the location you want showing up higher. Doing that should fix the issue of the SDK versions you installed not showing up when you run dotnet --info.
See The latest installed .NET SDK not found for complete instructions.
Answer above by Maira is correct and fixed the issue however for those that need a little help go to start menu, type "path" and select "Edit the System Environment variables". When that opens, under the "Advanced" tab click "Environment Variables".
Under System Variables find the "Path" variable and click "Edit". Find "C:\Program Files\dotnet" and click "Move Up" so that it is above the (x86) variable.
I managed to find the answer to this problem, and anyone else who is having this problem can most likely fix it with this solution too! So the reason it breaks is because of the way the .NET Core SDK installer works, it does not install the SDK correctly for some reason, so you have to do it manually. Go to this link, where you would normally get the installer for the SDK but rather than downloading the normal version, download the binaries version. It should download as a .zip, so extract it and then copy the contents of the folder. Go to C:\Program Files (x86)\dotnet\ and then remove it's contents, finally paste your clipboard into the folder. Now try it out, open a new command prompt or PowerShell, and type dotnet --info. It should tell you that you have all the SDK's and Runtimes installed. Keep in mind, you will have to download the newest version of the binaries, that way you have the latest version of the SDK's.
The reason this works is that you are manually pasting the SDK's into the folder, if anyone could start a ticket for the installer to Microsoft, {EDIT: MS created an internal ticket and this answer is wrong. See next answer End Edit} that would be great, and link them to this post so that they can understand what's going on. Some of you might have come here because you are fed up with reading Microsoft documentation and to be honest, so was I! Now this might not fix all the problems you are having, for example, I am still having problems with visual studio and their .NET implementation but if I or anyone figures it out, I will add it to this answer. Hope you have a great day, bye!
dotnet do not seem to match well with SDKs / runtimes with 32-bits and 64-bits. If you have both variants and want to only use the 64-bits (or generally, cant list up any SDK-s), you can try this :
Inside folder : C:\Program Files (x86)
Rename folder 'dotnet' to 'dotnet_x68'
Inside a shell (remember to either run command 'refreshenv' from Chocolatey for example to refresh your environment, if you have choco installed.. )
Enter now this command :
dotnet --info
Also list the SDKS :
dotnet --list-sdks
This fixed up my development environment. Note that if you want to use dotnet against x86 system, you might consider to instead uninstall x64 variants of dotnet runtime and sdks as dotnet do not seem to work very good from command line with a mix of them both (and avoid renaming the x86 folder of dotnet of course as suggested above.
I found that I had two program files, One called Program Files (x86) and one called Program Files. I went to Settings, About and looked at my System Type. I have a 64-Bit operating system and so I went into Program Files (x86) and found another dotnet folder. I deleted the dotnet folder and restarted Visual Studio. It Worked after that.
If you get this issue like I did on a ARM based Mac M1 or M2 then do the following.
remove this directory completely /usr/local/share/dotnet
run the installer package again
I believe this issue happened when I accidentally installed dotnet-ef x64 instead of arm64.

Error when trying to use .NET Generate Assets for Building and Debug in VSCode

I'll make this brief, below is the main issue I'm having.
I'm learning C# again so I can expand my skillset. Long story short, the tutorial I was following was showing the viewer how to use the above command from VSCode's command palette.
Whenever I try to use said command to generate the files it should, I get the error: "Unable to generate assets to build and debug. OmniSharp server is not running."
Thus far I have tried:
Uninstalling and reinstalling VSCode
Uninstalling and reinstalling the C# Extension in VSCode
Added C:\Windows\System32 to my PATH environment variable
Doing the above plus completely deleting the original project folder, restarting my computer, and remaking the simple "Hello world" print program created using "dotnet new console", inside of a workspace.
I am using:
Windows 10 Pro
Visual Studio Code 1.48.2
.NET SDK 3.1.401
I'm not sure what other information may be necessary, and I've looked through other similar questions, but nothing I try works, even after restarting my machine. I'm at a loss frankly.
Turns out the C# Extension on the current version is just buggy and not working right. Downloading an older version (1.21.16) and installing from VSIX seems to have somewhat fixed the previous issue. At the very least the error message has changed to something else.
For anyone also having this issue, I recommend trying what I did.

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

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)
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.
After closing it, re-install the .NET Core SDK.
You must be able to use it now.
It worked for me.
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.
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!
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!
2- Type in #ext:ms-dotnettools.csharp to search dotnet tools!
3- Scroll down until you find "Omnisharp: Dotnet Path" and click Edit in settings.json link!
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!
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!
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.
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.
Working on Mac M1. I was facing the same issue when I open the project in VSCode. This is how I resolved
Steps:
I quit my VS Code
I reinstalled dotnet SDK
I restarted my project
Initially, when I installed sdk, my VSCode was open, might be that was causing the issue.
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
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
My issue was I was using .Net version 5 on Apple silicon, when I tried .Net 6 the problem got solved.
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
quit VS code. quit attached program (unity, etc). open originally attached program. Open VS code (assets > open c# project).
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.
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
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.
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:
Close VS Code
Install .NET Core SDK
Re-install the extension (in my case)
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.
You can try using homebrew
Install homebrew https://brew.sh
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Close Visual Studio Code
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
Run sudo xcodebuild -license accept
Repeat brew install --cask dotnet-sdk
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
Changing System Environment Variable Path from C:\Program Files (x86)\dotnet to C:\Program Files\dotnet fixed the problem for me.
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.
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
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
Click on the error that is shown on your VS Code
Get into Settings of the error
Download it and you are all set

C# dotnet not being recognized

I've been trying to run a C# project in Visual Studio and keep getting hit with the error:
'"dotnet.exe"' is not recognized as an internal or external command,
operable program or batch file.
From what I've seen online, several people have managed to fix this by messing around with the SDK or with the 'path' environment variables in Window's System properties tab. The problem is, I have no idea what any of these system settings and specifications do, and I can't get a clear answer.
I can tell that VS isn't able to get dotnet working, so what ideas come to mind to fix this error?
Install the DotNet Core Runtime or SDK (I use latest version)
The SDK has all the tools needed for development (including the runtime), while the Runtime is needed for running dotnet core applications.
After installation, you will need to restart the PC yourself so that the data entered in the PATH variable are available
Runtime link
Check if you have %ProgramFiles%\dotnet\ folder in your PC, that's where the dotnet.exe file should be.
If you found none, that mean you have not installed .NET Core SDK/Runtime. As you have VS, I am assuming you are writing some code with it, you should install the SDK from here.
If you have the folder but still have the problem, go to your Environment Variable, add that folder to the end of PATH variable and restart the PC.

Categories

Resources