How to install .NET Framework SDK on .NET 5 SDK Docker image (Windows container)

  .net, .net-core, docker, windows

I have .NET 5 app, but a lot of project dependencies are still in .NET Framework 4.7.2 world…

I need to dockerize this app (for Windows Containers for now – this is the first step), but copying C:Program Filesdotnet from image into did not change anything and I still cannot build csproj file.

My Dockerfile:

FROM AS base

FROM AS framework-sdk

FROM AS build

# Copy the .NET Framework from framework-sdk image
ENV DOTNET_PATH="C:Program Filesdotnet"
COPY --from=framework-sdk ${DOTNET_PATH} ${DOTNET_PATH}


RUN dotnet restore (...)
COPY . .


FROM build AS publish
RUN dotnet publish "xx.csproj" -c Release -o /app/publish --no-restore

I also tried to install chocolatey to install .NET Framework SDK, but choco needs .NET Framework 4.0…
And I can’t install .NET Framework -> RUN pwsh -Command Install-WindowsFeature .NET-Framework-45-Features gives me error:
The term 'Install-WindowsFeature' is not recognized

Please note that pwsh is PoweShell Core. And even if I will install .NET Framework 4.0/4.5 I still need to "restart" machine.

Do you have some suggestions or maybe there are some docker images with .NET Framework and .NET 5 runtime and .NET Framework SDK and .NET 5 SDK?

Source: Windows Questions