'Bug in Azure devops pipeline/VS templates/dockerfile?
Trying to deploy a multi-project app to azure using pipelines. After trying various combinations (pipeline log is showing about 75/80 runs in the last couple of days), it looks like the problem is with the Dockerfile by Visual Studio 2019 or with the Azure Pipeline somewhere.
Here's what I've narrowed it down to:
Project A-
- create a vs asp.net core webapp project, say test1sp,
- select the checkbox which says create solution and project in the same folder,
- select docker support (I selected Linux) or add it later
- no code added, the boilerplate code runs fine as-is
- add it to GitHub
- create a project/pipeline in azure, source Github, I use the classic editor without YAML
- create a docker build/push task and setup, I choose the most basic options, subscriptions, etc.
- build works great, I also added a deploy to app service task and it deploys to the app service
Project B - my project is called demo8
Same as project A, except for step #2 - do NOT select create solution and project in the same folder. Follow the rest of the steps and now you should get this error.
Step 7/17 : COPY ["demo8/demo8.csproj", "demo8/"]
...
...
##[error]COPY failed: file not found in build context or excluded by .dockerignore: stat demo8/demo8.csproj: file does not exist
It works fine on localhost/docker. So, I'm guessing maybe vs2019 uses some more tolerant implementation to patch it over. Or, there's a problem with azure's implementation or something else?
I am relatively new to Dockerfile editing and see lots of detailed/complex scenarios, hopefully, someone can shed some light on how to get it working?
Here's a screenshot of the project files/structure:
UPDATE - Moving the Dockerfile to the solution folder in project B makes it work in azure BUT
- then it does NOT work in Visual Studio, no debugging, etc.
- make a copy of Dockerfile in project & parent folders ( + keep in sync )
- BUT if your solution has multiple projects like mine then
- you have to name the Dockerfile different to have unique names in the parent folder
- and modify the pipelines to use respective file names
Posting it here in case it helps someone.
Solution 1:[1]
The code in the Dockerfile must have the relative path to the folder level that the Dockerfile is in.
Tow ways to solve the problem. One is the change the code in the Dockerfile, for the project B, you can change the COPY code like this:
COPY ["demo8.csproj", "demo8/"]
Another way is to move the Dockerfile to the path that matches your COPY code. But in this way, it may affect other codes in your Dockerfile.
And you'd better plan your projects in different folders and create the Dockerfile for each project in different folders.
Solution 2:[2]
I just ran into this problem with a default console app in VS2022. I fixed it by changin the "Build context" parameter in the ADO build pipeline's Docker "build and push" step from the default of ** to **/.. so that the working directory was the solution folder, which matches VS (AFAIK).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Charles Xu |
| Solution 2 | Josh |

