Several potential fixes for the missing .NET SDK error (Docker and .NET Core)
There have been many people asking about this on Stack Overflow, and none of the answers there brought me closer to resolving the problem, which, it later transpired, was caused by something really silly I’d overlooked. When running ‘docker-compose up’ in the Docker CLI, for a .NET Core service, the output reports that it cannot find an installed SDK:
It was not possible to find any installed .NET Core SDKs
Did you mean to run .NET Core SDK commands? Install a .NET Core SDK from:
https://aka.ms/dotnet-download
The error message can be misleading, as the cause isn’t necessarily a missing SDK. In my case, the cause was missing dependencies that were almost entirely unrelated to the SDK itself. I tried the following:
Check the SDK image is installed
The most obvious thing to check is that the SDK it’s looking for actually exists on the local system. Using ‘dotnet –info’, we can get a list of SDKs currently installed. Removing the Docker image for the relevant one and pulling it again from the official repository could be a solution if the image was corrupted somehow.
docker pull mcr.microsoft.com/dotnet/sdk:6.0
Check references to the SDK in the Dockerfile
Are the correct .NET base images and versions being referenced in the Dockerfile? Again, the ‘dotnet –info’ command will provide the image names and version numbers, and they can be checked against the ones being referenced in the Dockerfile.
Check entry points
As I’ve said, the cause isn’t always a missing SDK or an incorrect reference to it. Sometimes the same error message will appear if Docker can’t find the entry point for the service it’s trying to run - basically the EXE or DLL for the compiled application/service. This would be caused by an incorrect file path somewhere in the Dockerfile. To check for this, I opened the command line for the Docker image I was trying to run, and used the usual Linux commands to inspect its filesystem.
Getting more details in Visual Studio’s PowerShell
Run ‘docker build -t’ in the PowerShell window in Visual Studio. This might provide more specific exception messages pointing to the cause of the problem.
In my case, it displayed the following somewhere in the output:
warning MSB3245: Could not resolve this reference. Could not locate the assembly "*System.Configuration*". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [/src/Application.Web/Application.Web.csproj]
Visual Studio solution with multiple projects
In my case, I encountered the problem because another project in the Visual Studio solution (Application.Common) provided the dependencies for the one I was attempting to build (Application.Web). What I was doing wrong was trying to build and run Application.Web using a docker-compose.yml file within that project’s directory, without referencing Application.Common or anything else in the solution directory.
As a first step, I shifted docker-compose.yml and Dockerfile to the solution’s root directory. Next, I added several lines to copy the entire solution to the virtual directory before building the projects/dependencies that were needed. e.g.
[...]
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src
COPY *.sln ./
COPY Application.Web/Application.Web.csproj Application.Web/
COPY . .
RUN dotnet restore Application.Web/Application.Web.csproj
WORKDIR /src/Application.Web
[...]
Then, using the following command, I was able to build the service (and its dependencies) and run its image in the Docker container:
docker-compose up --build