Using `WithReference` on a resource that depends on another resource annoated `ExcludeFromManifest` fails
- Dominant language
- C#
- Stars
- 6.3k
- Forks
- 991
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 201
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Describe the bug
When a resource is marked `ExcludeFromManifest`, it should be excluded from the publish step.
However, if you reference that resource from another resource using `WithReference`, it appears to be considered a dependency in the pipeline graph during `aspire deploy` or `aspire do`.
Example:
```c#
var mcpInspector = builder.AddMcpInspector("mcp-inspector", options =>
{
options.InspectorVersion = "0.18.0";
})
.WithMcpServer(mcp, path: "/");
mcp.WithReference(mcpInspector);
```
The `McpInspectorResource` is marked excluded from manifest in the toolkit.
Since `mcp` references `mcpInspector`, you will get an error during deployment:
```
❯ aspire deploy
13:26:27 (pipeline-execution) → Starting pipeline-execution...
13:26:27 (pipeline-execution) ✗ [ERR] Container app context not found for resource mcp-inspector.
13:26:27 (pipeline-execution) ✗ Failed
```
See https://github.com/CommunityToolkit/Aspire/issues/1093
### Expected Behavior
It should be safe to reference an excluded resource, and should be a no-op (no reference is created/maintained).
Otherwise, the error should be more clear. I thought initially it was an ACA deployment error.
### Steps To Reproduce
It should be trivial to reproduce but there's an example AppHost I have here:
https://github.com/kamranayub/pluralsight-course-mcp-in-practice/blob/ba0c08baf11817c7ae8d0b757935e6d8c25566cc/everything-demo/Globomantics.Demo.AppHost/AppHost.cs#L126-L136
### Exceptions (if any)
_No response_
### .NET Version info
_No response_
### Anything else?
**Workaround**
Add a conditional for `IsRunMode` before adding the reference:
```c#
var mcpInspector = builder.AddMcpInspector("mcp-inspector", options =>
{
options.InspectorVersion = "0.18.0";
})
.WithMcpServer(mcp, path: "/");
if (builder.ExecutionContext.IsRunMode) {
mcp.WithReference(mcpInspector);
}
```
Contributor guide
Research direction
Start with the linked AppHost.cs reproduction around lines 126-136 and run aspire deploy or aspire do with the WithReference and ExcludeFromManifest combination. Trace how the dependency graph handles the excluded mcp-inspector resource. Done means referencing an excluded resource is a no-op or produces a clear error instead of failing with a missing container app context.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- cloud, devops
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100