There is an error in RUN dotnet build
within Dockerfile generated by Visual Studio when I build it. here is the generated Dockerfile:
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["API/API.csproj", "API/"]
COPY ["Service/Service.csproj", "Service/"]
COPY ["Extentions/Extensions.csproj", "Extentions/"]
COPY ["DTO/DTO.csproj", "DTO/"]
COPY ["Core/Core.csproj", "Core/"]
COPY ["Data/Data.csproj", "Data/"]
RUN dotnet restore "API/API.csproj"
COPY . .
WORKDIR "/src/API"
RUN dotnet build "API.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "API.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "API.dll"]
And this is the structure of my solution.
I found that to build that Dockerfile I have to call it from the root of the solution like this:
docker build -t mysolution:tag -f api/Dockerfile .
But there is just an error in the following line of the Dockerfile:
RUN dotnet build "API.csproj" -c Release -o /app/build
I tried to change "API.csproj" to something else such as "/API/API.csproj" or even omit it but I got an error at that specific line again.
And finally this the whole error:
[ ] Building 8.9s (20/22)
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 876B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 35B 0.0s
=> [internal] load metadata for mcr.microsoft.com/dotnet/sdk:5.0 3.1s
=> [internal] load metadata for mcr.microsoft.com/dotnet/aspnet:5.0 0.0s
=> [base 1/2] FROM mcr.microsoft.com/dotnet/aspnet:5.0 0.0s
=> [internal] load build context 0.2s
=> => transferring context: 111.97kB 0.2s
=> [build 1/12] FROM mcr.microsoft.com/dotnet/sdk:5.0@sha256:f096bacde1255be2a7b5dad325167f1e76f799b7ee5ee4f5b6 0.0s
=> CACHED [base 2/2] WORKDIR /app 0.0s
=> CACHED [final 1/2] WORKDIR /app 0.0s
=> CACHED [build 2/12] WORKDIR /src 0.0s
=> CACHED [build 3/12] COPY [API/API.csproj, API/] 0.0s
=> CACHED [build 4/12] COPY [Service/Service.csproj, Service/] 0.0s
=> CACHED [build 5/12] COPY [Extentions/Extensions.csproj, Extentions/] 0.0s
=> CACHED [build 6/12] COPY [DTO/DTO.csproj, DTO/] 0.0s
=> CACHED [build 7/12] COPY [Core/Core.csproj, Core/] 0.0s
=> CACHED [build 8/12] COPY [Data/Data.csproj, Data/] 0.0s
=> CACHED [build 9/12] RUN dotnet restore "API/API.csproj" 0.0s
=> CACHED [build 10/12] COPY . . 0.0s
=> CACHED [build 11/12] WORKDIR /src/API 0.0s
=>ERROR [build 12/12] RUN dotnet build "API.csproj" -c Release -o /app/build 5.5s
------
> [build 12/12] RUN dotnet build "API.csproj" -c Release -o /app/build:
#20 0.814 Microsoft (R) Build Engine version 16.11.2 f32259642 for .NET
#20 0.814 Copyright (C) Microsoft Corporation. All rights reserved.
#20 0.814
#20 1.233 Determining projects to restore...
#20 2.568 All projects are up-to-date for restore.
#20 4.241 DTO -> /app/build/DTO.dll
#20 4.506 Extensions -> /app/build/Extensions.dll
#20 4.556 Core -> /app/build/Core.dll
#20 4.965 Service -> /app/build/Service.dll
#20 5.228 Data -> /app/build/Data.dll
#20 5.480 /src/API/Contracts/V1.cs(12,42): error CS8652: The feature 'constant interpolated strings' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version. [/src/API/API.csproj]
#20 5.480 /src/API/Contracts/V1.cs(13,39): error CS8652: The feature 'constant interpolated strings' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version. [/src/API/API.csproj]
#20 5.484
#20 5.484 Build FAILED.
#20 5.485
#20 5.485 /src/API/Contracts/V1.cs(12,42): error CS8652: The feature 'constant interpolated strings' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version. [/src/API/API.csproj]
#20 5.485 /src/API/Contracts/V1.cs(13,39): error CS8652: The feature 'constant interpolated strings' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version. [/src/API/API.csproj]
#20 5.485 0 Warning(s)
#20 5.485 2 Error(s)
#20 5.485
#20 5.485 Time Elapsed 00:00:04.62
------
executor failed running [/bin/sh -c dotnet build "API.csproj" -c Release -o /app/build]: exit code: 1
CodePudding user response:
Constant interpolated strings are part of c# 10 so it tied with .net 6. You need to use appropriate images for you dockerfile.
Use mcr.microsoft.com/dotnet/aspnet:6.0 for base and mcr.microsoft.com/dotnet/sdk:6.0 for build.