my folder structure of the ASP.NET web app looks like this:
MyApp.Backend/
├── src/
│ ├── MyApp/
│ │ ├── MyApp.csproj
│ │ └── Dockerfile
│ ├── Core/
│ │ ├── MyLibrary1/
│ │ │ └── MyLibrary1.csproj
│ └── External/
│ ├── MyLibrary2/
│ │ └── MyLibrary2.csproj
So dockerfile is in the MyApp.Backend/src/MyApp/dockerfile.
Dockerfile itself looks like this (generated from both Rider and VS2022):
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER $APP_UID
WORKDIR /app
EXPOSE 8080
EXPOSE 8081
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
# Copy project files
COPY ["src/MyApp/MyApp.csproj", "src/MyApp/"]
COPY ["src/Core/MyLibrary1/MyLibrary1.csproj", "src/Core/MyLibrary1/"]
COPY ["src/External/MyLibrary2/MyLibrary2.csproj", "src/External/MyLibrary2/"]
# Restore NuGet packages
RUN dotnet restore "src/MyApp/MyApp.csproj"
# Copy everything else
COPY . .
WORKDIR "/src/src/MyApp"
# etc.....
No matter what I do, or how do I run it, dockerfile can never find the project files:
#9 [build 4/13] COPY [MyApp/MyApp.csproj, MyApp/]
#9 ERROR: failed to calculate checksum of ref 828adade-9126-45c5-a536-dc1f57fd1350::4yps4ixymnuqpupflyaiyicxz: "/MyApp/MyApp.csproj": not found
#10 [build 9/13] COPY [External/MyLibrary2/MyLibrary2.csproj, External/MyLibrary2/MyLibrary2.csproj/]
#10 ERROR: failed to calculate checksum of ref 828adade-9126-45c5-a536-dc1f57fd1350::4yps4ixymnuqpupflyaiyicxz: "/External/MyLibrary2/MyLibrary2.csproj": not found
#11 [build 8/13] COPY [Core/MyLibrary1/MyLibrary1.csproj, Core/MyLibrary1/]
#11 ERROR: failed to calculate checksum of ref 828adade-9126-45c5-a536-dc1f57fd1350::4yps4ixymnuqpupflyaiyicxz: "/Core/MyLibrary1/MyLibrary1.csproj": not found
I’ve tried playing around the WORKDIR command but to no avail. This is relatively standard folder structure of a microservice but docker just seems it cannot find the related csproj files.
The pipeline yaml file (part of it):
variables:
dockerfilePath: 'MyApp.Backend/src/MyApp/Dockerfile'
- task: Docker@2
displayName: Build and push an image to container registry
inputs:
command: buildAndPush
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
$(tag)