microsoft / DockerTools

Tools For Docker, including Visual Studio Provisioning and Publishing
Other
173 stars 26 forks source link

VS2022 ASP.NET Core 2.1 Docker Container Attach Error #432

Open aligoren opened 5 days ago

aligoren commented 5 days ago

Hi, I want to dockerize an old ASP.NET Core 2.1 project using VS2022. The project's Dockerfile and docker compose files are generated. However, no matter what I do, I keep seeing the following error message on Docker Desktop:

2024-06-27 16:57:00 Did you mean to run dotnet SDK commands? Please install dotnet SDK from:
2024-06-27 16:57:00   https://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409

Here is the Dockerfile generated by VS2022.

#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:2.1 AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/sdk:2.1 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["UserApi.Service/UserApi.Service.csproj", "UserApi.Service/"]
RUN dotnet restore "./UserApi.Service/UserApi.Service.csproj"
COPY . .
WORKDIR "/src/UserApi.Service"
RUN dotnet build "./UserApi.Service.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./UserApi.Service.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "UserApi.Service.dll"]

For example this one

image

The message was the same

WebApplication1_1 | Did you mean to run dotnet SDK commands? Please install dotnet SDK from:
WebApplication1_1 |   https://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409

What is my problem here?

I did everything. I deleted every folder in the project. As I said, I created an empty project and still getting this issue.

Shouldn't I use VS2022 to develop .NET Core 2.1 apps?

Best regards

aligoren commented 5 days ago

I ran these commands in the Docker container;

dotnet --list-runtimes
Microsoft.AspNetCore.All 2.1.30 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.30 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.30 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

This worked but dotnet --list-sdks couldn't installed.

dotnet --list-sdks
#

It returns nothing

Best regards

NCarlsonMSFT commented 5 days ago

There is a regression in 17.10 for debugging against older versions of .NET. There is a fix coming in the next 17.11 preview, or there is a workaround example here: https://github.com/NCarlsonMSFT/ExampleASPNet3_1OnVS17_10