Skip to main content

Azure DevOps Docker build error–No such file or directory

When trying to build a new .NET core project using Azure DevOps it failed with the following error message:

Step 6/16 : COPY ["DockerWebApplication1/DockerWebApplication1.csproj", "DockerWebApplication1/"]
COPY failed: stat /var/lib/docker/tmp/docker-builder590338138/DockerWebApplication1/DockerWebApplication1.csproj: no such file or directory
##[error]COPY failed: stat /var/lib/docker/tmp/docker-builder590338138/DockerWebApplication1/DockerWebApplication1.csproj: no such file or director
The problem is that the COPY command is using the wrong folder to COPY from. To fix it, update your Docker Build task:
  • Uncheck the “Use Default Build Context” checkbox
  • Set  the “Build Context” field to "$(System.DefaultWorkingDirectory)"