The command could not be loaded, possibly because: ... No .NET SDKs were found.
in Docker means you ran an SDK command such as dotnet build,
dotnet publish or dotnet ef in an image that holds only the .NET
runtime. The aspnet and runtime images run apps; they cannot build
them. Build in mcr.microsoft.com/dotnet/sdk and copy the output into the
runtime image.
That is the multi-stage Dockerfile: a FROM ...sdk:10.0 AS build stage that
publishes, and a final stage on aspnet:10.0 or runtime:10.0 that
copies the publish folder and runs dotnet YourApp.dll.
The error
docker run --rm --name fix8-bld-rt1 mcr.microsoft.com/dotnet/aspnet:10.0 dotnet build
The command could not be loaded, possibly because:
* You intended to execute a .NET application:
The application 'build' does not exist or is not a managed .dll or .exe.
* You intended to execute a .NET SDK command:
No .NET SDKs were found.
Download a .NET SDK:
https://aka.ms/dotnet/download
Learn about SDK resolution:
https://aka.ms/dotnet/sdk-not-found
The exit code was 155. dotnet ef in runtime:10.0 printed the same
text with 'ef' in place of 'build', and a Dockerfile whose only
stage was FROM mcr.microsoft.com/dotnet/aspnet:10.0 with
RUN dotnet publish -c Release -o /app failed the build with
exit code: 155 after the same lines.
Why it happens
dotnet is a small host program. Given a word that is not a .dll, it
looks for an SDK to hand the command to. dotnet --info in the
aspnet:10.0 image lists two runtimes, Microsoft.AspNetCore.App 10.0.13
and Microsoft.NETCore.App 10.0.13, and under SDKs says
No SDKs were found. With no SDK, the host cannot tell whether you meant an app
named build or an SDK command, so it prints both possibilities.
This is not the "You must install or update .NET" message, which appears when an app needs a
runtime that is missing. Here the runtime is fine; the build tools were never in the image.
dotnet ef in runtime:10.0 failed with the same message; it needs
the SDK and, on top of it, the dotnet-ef tool installed in that stage.
The fix
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
WORKDIR /src
COPY Hello/ .
RUN dotnet publish -c Release -o /app
FROM mcr.microsoft.com/dotnet/runtime:10.0
WORKDIR /app
COPY --from=build /app .
ENTRYPOINT ["dotnet", "Hello.dll"]
Built and run, this image printed Hello, World! and exited with 0. For a web
app, make the final stage aspnet:10.0. On this machine docker image ls showed the SDK image at 1.25GB
against 340MB for aspnet:10.0 and 300MB for runtime:10.0,
which is why it stays in the build stage and never ships.
How it was reproduced
docker run of dotnet build in aspnet:10.0 and of
dotnet ef in runtime:10.0, then a one-stage Dockerfile for a
dotnet new console -n Hello project (net10.0), built with
docker build --progress=plain -t fix8-bld-p5 -f fix8-bld-p5/Dockerfile fix8-bld-ctx.
Images carried .NET 10.0.13; Docker Desktop engine 29.9.2. Container, tag and folder names are
this test's own.
Frequently asked
- Does the dotnet aspnet Docker image include the SDK?
- No. mcr.microsoft.com/dotnet/aspnet and dotnet/runtime contain only runtimes. dotnet build and dotnet publish need mcr.microsoft.com/dotnet/sdk.
- Can I run dotnet ef in the dotnet runtime Docker image?
- No. dotnet ef in mcr.microsoft.com/dotnet/runtime:10.0 failed with No .NET SDKs were found. It needs the SDK and also the dotnet-ef tool installed in that stage.
- What does No .NET SDKs were found mean?
- The dotnet host found runtimes but no SDK, so it cannot run SDK commands. Install an SDK, or in Docker build in the sdk image and run in the runtime image.
More decoded errors in the Fixes category. If the app
starts but asks for Microsoft.AspNetCore.App, see
the runtime image post.