I have a project targeting .NET 6 and .NET 7.
My Dockerfile
looks like this:
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
WORKDIR /app
# Copy everything
COPY . ./
# Restore as distinct layers
RUN dotnet restore -p:TargetFramework=net6.0
# Build and publish a release
RUN dotnet publish --framework net6.0 -p:TargetFramework=net6.0 -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "MyApp.dll"]
While the dotnet publish
command works on my local machine outside Docker build, it results in this error during the Docker build:
Step 5/9 : RUN dotnet publish --framework net6.0 -p:TargetFramework=net6.0 -c Release -o out
---> Running in dfb3663dd3ca
MSBuild version 17.3.2+561848881 for .NET
Determining projects to restore...
/usr/share/dotnet/sdk/6.0.405/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(144,5): error NETSDK1045: The current .NET SDK does not support targeting .NET 7.0. Either target .NET 6.0 or lower, or use a version of the .NET SDK that supports .NET 7.0. [/app/MyApp.csproj]
The command '/bin/sh -c dotnet publish --framework net6.0 -p:TargetFramework=net6.0 -c Release -o out' returned a non-zero code: 1
I could even specify abc
as TargetFramework
and it didn't complain aside the message shown already:
RUN dotnet publish -f:abc -c Release -o out
It also seems to ignore this global.json
:
{
"sdk": {
"version": "6.0.0",
"rollForward": "latestMinor",
"allowPrerelease": false
}
}