Reputation: 113
I installed the SDK 5.0 for windows (just like in this video https://youtu.be/a6WPeTG1QEk) and it is actually present under C:\Programs Files\dotnet, but when I type dotnet new consol -o myApp in cmd it gives me the following error:
> PS D:\Programme\VSCodeNetCoreTest> dotnet new console
Could not execute because the application was not found or a compatible .NET SDK is not installed.
Possible reasons for this include:
* You intended to execute a .NET program:
The application 'new' does not exist.
* You intended to execute a .NET SDK command:
It was not possible to find any installed .NET SDKs.
Install a .NET SDK from:
https://aka.ms/dotnet-download
(This is in VSCode and has no -o myApp but it gives me the same error in cmd) I have added the dotnet directory to PATH and it still wont run.
What am I doing wrong?
Upvotes: 6
Views: 18407
Reputation: 21
I faced the same issue while creating Function apps in VS Code. I did the following:
Upvotes: 2
Reputation: 78
I am trying to create a dotnet console application in Visual Studio Code and getting the same error. Below are my findings & the solution that worked for me:
Problem: In VS code, c# files are not executing or unable to create dotnet console application from terminal.
Error: Could not execute because the application is not found or a compatible .Net SDk is not installed
I already have installed .Net SDK on my machine.
How to diagnose: In cmd, run command: dotnet --version -> Could not execute because the application is not found or a compatible .Net SDk is not installed...blablabla
run command: where dotnet -> C:\Program Files (x86)\dotnet\dotnet.exe C:\Program Files\dotnet\dotnet.exe
Root Cause: There are two exe files i.e. dotnet.exe present in c drive at different locations i.e.: C:\Program Files (x86)\dotnet C:\Program Files\dotnet
And in system environment variables - Path - both are added (x86) one being at first. As I am using 64 bit OS, I am supposed to use the later path for dotnet.exe.
Solution: Go to "Environment Variables" dialog from start menu, edit the system environment variable "Path"-
Check: Reopen cmd in admin mode & run command - dotnet --version -> 6.0.101
Reopen visual studio code & in terminal, open the folder where you want to place your c# console application, run command - dotnet new console -> obj, csproj, program.cs are now added in the folder. Add a simple C# code to Print "Hello World" in Program.cs & run.
Upvotes: 6
Reputation: 97
I just had the same issue, could not build using dotnet in vscode or local build agent but I could build using visual studio.
When running "dotnet build -v diag" in bash I found that there is an Environment Variable "MSBuildSDKsPath" that was set to a non existing version.
I tried changing it to a different version which did not work. In the end I just deleted it and that fixed my build.
Upvotes: 0
Reputation: 113
The exact details are discussed here: https://github.com/dotnet/sdk/issues/14916
TL:DR There were two dotnet.exe files in Program Files and Program Files(x86), that I had to delete both and reinstall via Visual Studio 2019 (porably not the only method).
Now there is only one dotnet.exe in Program Files and it finally works.
Upvotes: 3