6

Getting an error in the Azure DevOps Pipeline:

Step 7/17 : COPY ["demo6/demo6.csproj", "demo6/"]
COPY failed: file not found in build context or excluded by .dockerignore: stat demo6/demo6.csproj: file does not exist

NOTES-run the pipeline in diagnostics mode and the .sln file exists

##[debug]cwd=/home/vsts/work/1/s
##[debug]  /home/vsts/work/1/s/demo6.sln (file)
##[debug]  /home/vsts/work/1/s/demo6/demo6.csproj (file)

I have a multi-project Asp.Net Core solution with the folder structure and projects as follows:

demo6
 |--demo6/demo6.csproj
 |--demo6.api/demo6.api.csproj

The app is demo6 which references demo6.api which is a class library.

This is in GitHub in a repository demo6. I modified the autogenerated Dockerfile to add the extra demo6/ to see if that works but no.

Appreciate any help.

Dockerfile below:

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

FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["demo6/demo6.csproj", "demo6/"]
RUN dotnet restore "demo6/demo6.csproj"
COPY . .
WORKDIR "/src/demo6"
RUN dotnet build "demo6.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "demo6.csproj" -c Release -o /app/publish

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

Also tried this:

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

FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["demo6/demo6/demo6.csproj", "ddemo6/"]
RUN dotnet restore "ddemo6/demo6.csproj"
COPY . .
WORKDIR "/src/ddemo6"
RUN dotnet build "demo6.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "demo6.csproj" -c Release -o /app/publish

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

Got this error:

Step 7/17 : COPY ["demo6/demo6/demo6.csproj", "ddemo6/"]
COPY failed: file not found in build context or excluded by .dockerignore: stat demo6/demo6/demo6.csproj: file does not exist
##[error]COPY failed: file not found in build context or excluded by .dockerignore: stat demo6/demo6/demo6.csproj: file does not exist

here's the repo structureenter image description here

9
  • 1
    Does the docker build run properly when testing locally? Commented May 1, 2021 at 4:02
  • 1
    The way you have your file tree written, from the root, the path would be demo6/demo6/demo6.csproj Commented May 1, 2021 at 4:17
  • 1
    yes it worked after that i put it on github, created the pipeline Commented May 1, 2021 at 4:18
  • @khuynh, yes i tried that too and it didn't work Commented May 1, 2021 at 4:31
  • Hi @Kumar, based on the error message, it seems that cannot found the file on the path demo6/demo6.csproj, could you share a screenshot of the repo structure here? Thanks. Commented May 3, 2021 at 2:29

1 Answer 1

4

The reason of file not found error may be the relative path of the Dockerfile and the csproj are different. Try to set the Dockerfile in the root of the solution should solve your error.

Also you need to add a buildContext with the csproj folder.

buildContext: Path to the build context

Also, here is a case you can refer to.

One more possible cause of COPY failed: no source files were specified is .dockerignore file present in your workspace

Look for .dockerignore file because of docker’s CLI (command line interface) it sends context to the docker daemon to load the .dockerignore file.

If the .dockerignore file exist in the context than it might be possible there is exclude entry to ignore the build directory

# ignore or exclude build directory
*/build*
*/*/build*
Sign up to request clarification or add additional context in comments.

1 Comment

Based on this answer, I fixed my problem by unchecking "Use Default Build Context" in the Docker build task (Classic pipeline). For YAML, I believe the equivalent is defaultContext: false. I left "Build Context" blank, which set the context to the root solution folder as the Dockerfile expected.

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.