PublishAsDockerFile() ignores DockerfileContext MSBuild property — Docker build context defaults to project directory instead of solution root
- Dominant language
- C#
- Stars
- 6.3k
- Forks
- 991
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 196
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Describe the bug
When using PublishAsDockerFile() on project resources in an Aspire AppHost and deploying with aspire deploy, the Docker build context is set to the project directory rather than honoring the MSBuild property defined in the Bm.PLCwatch.Worker.csproj. This causes all COPY instructions in the Dockerfile to fail with not found errors, because the Dockerfile paths are relative to the solution root (as generated by Visual Studio).
### Expected Behavior
When aspire deploy builds Docker images via PublishAsDockerFile(), it should read the MSBuild property from the project file and use it as the Docker build context. In this case, ..\ should resolve the build context to the solution root, matching the behavior of Visual Studio Container Tools when building locally.
Equivalent correct docker build command:
```
# From solution root
docker build -f ProjectA/Dockerfile .
```
### Steps To Reproduce
Solution structure:
```
SolutionRoot/
├── AppHost/
│ └── AppHost.cs
├── ProjectA/
│ ├── ProjectA.csproj
│ └── Dockerfile
├── ProjectB/
│ ├── ProjectB.csproj
│ └── Dockerfile
├── SharedLib/
│ └── SharedLib.csproj
├── DataAccess/
│ └── DataAccess.csproj
├── Entities/
│ └── Entities.csproj
└── ServiceDefaults/
└── ServiceDefaults.csproj
```
ProjectA .csproj:
```
Linux
..\
```
Dockerfile (generated by Visual Studio, lives in ProjectA/):
```
WORKDIR /src
COPY ["ProjectA/ProjectA.csproj", "ProjectA/"]
COPY ["SharedLib/SharedLib.csproj", "SharedLib/"]
COPY ["DataAccess/DataAccess.csproj", "DataAccess/"]
# ... paths relative to solution root
```
AppHost.cs:
```
builder.AddProject("project-a")
.PublishAsDockerFile();
builder.AddDockerComposeEnvironment("compose");
```
### Exceptions (if any)
Every COPY instruction fails:
```
ERROR: failed to calculate checksum of ref
"/ProjectA/ProjectA.csproj": not found
ERROR: failed to calculate checksum of ref
"/SharedLib/SharedLib.csproj": not found
ERROR: failed to calculate checksum of ref
"/DataAccess/DataAccess.csproj": not found
ERROR: failed to calculate checksum of ref
"/ServiceDefaults/ServiceDefaults.csproj": not found
```
### .NET Version info
• Aspire SDK: Aspire.AppHost.Sdk/13.1.2
• .NET SDK: 10.0
• OS: Windows
• Docker: Docker Desktop with BuildKit
### Anything else?
FYI:
Text have been generated with AI
I research this issue now for 2 day with and without the help of AI
Pls send help
Contributor guide
Assessment
This issue has not been assessed yet.