"Did you mean to run dotnet SDK commands? Please install dotnetsdk" in windows command prompt

17,547

Solution 1

Please, make sure you've installed SDK not just runtime.

enter image description here

UPDATE

This is what you will see on the server without SDK installed if you run dotnet.exe --list-sdks command

enter image description here

And this with SDK installed:

enter image description here

One needs to install SDK on a development machine to be able to build and run applications and runtime (usually on an application server or user machine) to be able to just run built applications.

Solution 2

In my case somehow I also had a C:\Program Files (x86)\dotnet with a runtime version there which was picked from Path instead of the SDK in C:\Program Files\dotnet

This was causing exactly the same error message + it was breaking solutions in Visual Studio (but not in Rider)

Solution 3

I was getting the same problem when I was trying to dockerize my .Net Core 2.2 Web API solution.

enter image description here

I was using the below images to build the images. Please note that place where the sdk(mcr.microsoft.com/dotnet/core/sdk:2.2) is used.

FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS base
WORKDIR /app
EXPOSE 5051
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS build

Apparently the order I was used is wrong, So I changed it as preceding .

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS base
WORKDIR /app
EXPOSE 5051
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
WORKDIR /src
........

RUN dotnet restore "Api.csproj"
WORKDIR "/src/Api"
COPY . .
WORKDIR "/src/Api"
RUN dotnet build "Api.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "Api.csproj" -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .

ENV ASPNETCORE_ENVIRONMENT DevStaging
ENV ASPNETCORE_URLS=http://+:5051

ENTRYPOINT ["dotnet", "Api.dll"]

This fixed my issue. Hope it helps.

Share:
17,547
user9057272
Author by

user9057272

Updated on July 29, 2022

Comments

  • user9057272
    user9057272 almost 2 years

    I have just installed dot net core sdk and runtime (2.2.1) on my system viz. a Windows Server 2012R2. I am trying to create a console app using the command prompt using

    dotnet new console
    

    but it says

    Did you mean to run dotnet SDK commands? Please install dotnetsdk

    Is there any other configurations needed. The Environment path variable also contains the following folder C:\Program Files\dotnet. I have not installed VS2017. Was trying to use VS Code

  • user9057272
    user9057272 about 5 years
    I have. I can see the sdk folder and contents in C:\Program Files\dotnet
  • BigMuzzy
    BigMuzzy about 5 years
    Do you have dotnet.exe file in that folder?
  • user9057272
    user9057272 about 5 years
    Yes..the dotnet.exe file is present
  • BigMuzzy
    BigMuzzy about 5 years
    what does it "say" if you run it from the command line with --version argument?
  • BigMuzzy
    BigMuzzy about 5 years
    You've said I quote "I have just installed dot net core sdk and runtime.." you actually don't need to install runtime if you installed SDK, I haven't check but if you installed SDK and then runtime the latter installation could "clean up" SDK and leave you with just runtime, in that case, the error you see would be expected behavior.
  • BigMuzzy
    BigMuzzy about 5 years
    @user9057272 Please see my updated answer, I think you'll be able to figure out your problem.
  • user9057272
    user9057272 about 5 years
    You are right. That is exactly what I had done. Removed and reinstalled the sdk only this time. Works perfectly. Thanks
  • Chris Lynch
    Chris Lynch almost 5 years
    +1 to the answer. I was going through updates to my system (I use Chocolaty), and the System Path value had C:\Program Files (x86)\DotNet higher than C:\Program Files\DotNet. Once I adjusted the ordering, DotNet --Version worked.
  • Rejwanul Reja
    Rejwanul Reja over 4 years
    This is best answer to vote +1. Thanks a lot for saving time.