1

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.

enter image description here

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
1
  • try explicity setting <LangVersion>8</LangVersion> in .csproj file Also, proper target framework (Application Tab) and Language Version (Build > Advanced) in project settings. Commented May 25, 2022 at 16:26

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Currently, I'm using .net 5 in my project. Should I upgrade to .net 6?
I'm not sure that you are using .net 5, at least in the API project where you are getting the error. If it is compiled locally that mean you are targeted on .net 6 and you have installed .net 6 sdk.
Target Framework has set to .net 5 <TargetFramework>net5.0</TargetFramework>. And there is no error when I run the project.
In that case you should have been specified langversion 10 in your project.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.