Skip to content

Fix WithReference to only use IResourceWithEndpoints#14254

Open
Falco20019 wants to merge 10 commits intomicrosoft:mainfrom
Falco20019:patch-1
Open

Fix WithReference to only use IResourceWithEndpoints#14254
Falco20019 wants to merge 10 commits intomicrosoft:mainfrom
Falco20019:patch-1

Conversation

@Falco20019
Copy link
Copy Markdown

@Falco20019 Falco20019 commented Jan 30, 2026

Description

This allows to use ContainerResource with WithReference. Currently the interface enforces IResourceWithServiceDiscovery while internally only using/needing IResourceWithEndpoints. For backwards compatibility I will leave the original ones although redundant.

Fixes #10286

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 30, 2026

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 14254

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 14254"

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Jan 30, 2026
Comment thread src/Aspire.Hosting/ResourceBuilderExtensions.cs Outdated
@davidfowl
Copy link
Copy Markdown
Contributor

Breaking change no?

@Falco20019
Copy link
Copy Markdown
Author

As the other interface inherits it, I wouldn't think so. I can't see the unit tests here in GitHub Actions right now and won't be near a PC before Monday. If they still work, it shouldn't be breaking.

@Falco20019
Copy link
Copy Markdown
Author

Breaking change no?

Ok, now I understand what you meant. It's not clashing with IResourceWithServiceDiscovery but with IResourceWithConnectionString. I will rename it to WithEndpoints to avoid issues but still give users some way to use it for simple cases.

@Falco20019
Copy link
Copy Markdown
Author

Falco20019 commented Feb 2, 2026

I sadly don't get it to compile locally on macOS with Docker Desktop following https://github.com/dotnet/aspire/blob/main/docs/machine-requirements.md

Neither through DevContainers nor natively as protoc always gives an error 139. So have to rely on the CI to see if it's working now.

I think offering WithEndpoints should be a sufficient workaround until the next breaking change, but I would love to have WithReference be adjusted to only use IResourceWithEndpoints and have the check to offer the ReferenceEnvironmentInjectionFlags.ServiceDiscovery done by pattern matching against IResourceWithServiceDiscovery (as already done). I therefore prepared it in a way, that allows for adjusting the existing WithReference method on 14.x :)

https://dev.azure.com/dnceng-public/public/_build/results?buildId=1276039&view=results seems to hint that no tests have been executed by the CI, is that normal?

@Falco20019 Falco20019 requested a review from eerhardt February 17, 2026 08:30
@Falco20019
Copy link
Copy Markdown
Author

@davidfowl Should be non-breaking now.

@davidfowl davidfowl closed this Mar 4, 2026
@davidfowl davidfowl reopened this Mar 4, 2026
@dotnet-policy-service dotnet-policy-service Bot added this to the 13.3 milestone Mar 4, 2026
@davidfowl davidfowl requested a review from sebastienros March 4, 2026 09:11
@davidfowl davidfowl closed this Mar 27, 2026
@davidfowl davidfowl reopened this Mar 27, 2026
@JamesNK
Copy link
Copy Markdown
Member

JamesNK commented Mar 27, 2026

For backwards compatibility I will leave the original ones although redundant.

Should they be made obsolete with a note that they'll be removed in the future?

@Falco20019
Copy link
Copy Markdown
Author

@JamesNK I think this would then show obsolete messages all over the place in all cases where the more specific interface is used, right?

Copy link
Copy Markdown
Member

@joperezr joperezr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a bunch for working on this @Falco20019! Here are some comments of the current state — the PR needs a rebase and has some test/doc issues we should fix before merging.

Comment thread src/Aspire.Hosting/ResourceBuilderExtensions.cs
Comment thread tests/Aspire.Hosting.Tests/WithEndpointsTests.cs Outdated
Comment thread src/Aspire.Hosting/ResourceBuilderExtensions.cs Outdated
Comment thread src/Aspire.Hosting/ResourceBuilderExtensions.cs
Comment thread src/Aspire.Hosting/ResourceBuilderExtensions.cs
Comment thread src/Aspire.Hosting/ResourceBuilderExtensions.cs
@Falco20019
Copy link
Copy Markdown
Author

Falco20019 commented Apr 7, 2026

@joperezr Thanks for the review. I hope I addressed all remarks. I sadly still have issues on macOS to get it built/tested, so had to make the adjustments untested and hoped for the results here in GH.

EDIT: Seems that I'm affected by grpc/grpc#38538
EDIT2: I see that #15599 already tries to workaround this issue. Sadly it's not on main yet. I could cherry-pick the merge commit to be able to run tests if it helps speed up things.

@Falco20019 Falco20019 requested a review from joperezr April 7, 2026 10:41
Copy link
Copy Markdown
Member

@joperezr joperezr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing the previous round of feedback! The XML docs and attributes look good now. Just two remaining issues in the tests that are causing the 5 CI failures — both are fallout from the merge with main (the scheme-based key change from #14626). Should be a quick fix!

Comment thread tests/Aspire.Hosting.Tests/WithEndpointsTests.cs
Comment thread tests/Aspire.Hosting.Tests/WithEndpointsTests.cs Outdated
Copy link
Copy Markdown
Member

@joperezr joperezr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @mitchdenny @davidfowl since this is appmodel, can you please take a look at the new API shape?

@Falco20019
Copy link
Copy Markdown
Author

Falco20019 commented Apr 21, 2026

@joperezr Thanks for the feedback. Since #15599 ended up on main, I might now be able to build the code base and run the tests locally. Should avoid more rounds than necessary.

EDIT: Still not working on macOS...

[2026-04-21T06:58:58.915Z] Stop (1 ms): Run in container: cat '/tmp/devcontainers-fab3de7f-06fb-4a1c-862b-0d779dd34aee1776754476846/env-loginInteractiveShell.json'
[2026-04-21T06:58:58.915Z] Start: Run in container: /bin/sh -c dotnet restore
[2026-04-21T06:58:59.062Z] A fatal error was encountered. The library 'libhostpolicy.so' required to execute the application was not found in '/workspaces/aspire/.dotnet/shared/Microsoft.NETCore.App/10.0.5'.
[2026-04-21T06:58:59.182Z] 
What's next:
    Try Docker Debug for seamless, persistent debugging tools in any container or image → docker debug 0a780387687938185d38796158267408401531cfa680e80b898483e56e3be3ed
    Learn more at https://docs.docker.com/go/debug-cli/
[2026-04-21T06:58:59.183Z] Stop (268 ms): Run in container: /bin/sh -c dotnet restore
[2026-04-21T06:58:59.184Z] onCreateCommand from devcontainer.json failed with exit code 131. Skipping any further user-provided commands.
[2026-04-21T06:58:59.185Z] Error: Command failed: /bin/sh -c dotnet restore
[2026-04-21T06:58:59.185Z]     at E (/Users/dejhbk0l/.vscode/extensions/ms-vscode-remote.remote-containers-0.454.0/dist/spec-node/devContainersSpecCLI.js:233:157)
[2026-04-21T06:58:59.185Z]     at async Promise.allSettled (index 0)
[2026-04-21T06:58:59.185Z]     at async Jq (/Users/dejhbk0l/.vscode/extensions/ms-vscode-remote.remote-containers-0.454.0/dist/spec-node/devContainersSpecCLI.js:235:119)
[2026-04-21T06:58:59.185Z]     at async Hd (/Users/dejhbk0l/.vscode/extensions/ms-vscode-remote.remote-containers-0.454.0/dist/spec-node/devContainersSpecCLI.js:224:4668)
[2026-04-21T06:58:59.185Z]     at async xd (/Users/dejhbk0l/.vscode/extensions/ms-vscode-remote.remote-containers-0.454.0/dist/spec-node/devContainersSpecCLI.js:224:4013)
[2026-04-21T06:58:59.185Z]     at async Kd (/Users/dejhbk0l/.vscode/extensions/ms-vscode-remote.remote-containers-0.454.0/dist/spec-node/devContainersSpecCLI.js:224:3020)
[2026-04-21T06:58:59.185Z]     at async PZ (/Users/dejhbk0l/.vscode/extensions/ms-vscode-remote.remote-containers-0.454.0/dist/spec-node/devContainersSpecCLI.js:667:2823)
[2026-04-21T06:58:59.185Z]     at async YZ (/Users/dejhbk0l/.vscode/extensions/ms-vscode-remote.remote-containers-0.454.0/dist/spec-node/devContainersSpecCLI.js:666:8941)
[2026-04-21T06:58:59.185Z]     at async /Users/dejhbk0l/.vscode/extensions/ms-vscode-remote.remote-containers-0.454.0/dist/spec-node/devContainersSpecCLI.js:483:1917
[2026-04-21T06:58:59.190Z] Stop (600 ms): Run: /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) /Users/dejhbk0l/.vscode/extensions/ms-vscode-remote.remote-containers-0.454.0/dist/spec-node/devContainersSpecCLI.js run-user-commands --user-data-folder /Users/dejhbk0l/Library/Application Support/Code/User/globalStorage/ms-vscode-remote.remote-containers/data --container-session-data-folder /tmp/devcontainers-fab3de7f-06fb-4a1c-862b-0d779dd34aee1776754476846 --workspace-folder /Users/dejhbk0l/GitRepos/liv3/aspire --id-label devcontainer.local_folder=/Users/dejhbk0l/GitRepos/liv3/aspire --id-label devcontainer.config_file=/Users/dejhbk0l/GitRepos/liv3/aspire/.devcontainer/devcontainer.json --container-id 0a780387687938185d38796158267408401531cfa680e80b898483e56e3be3ed --log-level debug --log-format json --config /Users/dejhbk0l/GitRepos/liv3/aspire/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --skip-non-blocking-commands true --prebuild false --stop-for-personalization true --remote-env REMOTE_CONTAINERS_IPC=/tmp/vscode-remote-containers-ipc-f434040b-ecc6-46e6-88a3-8e7aee2a6d12.sock --remote-env SSH_AUTH_SOCK=/tmp/vscode-ssh-auth-f434040b-ecc6-46e6-88a3-8e7aee2a6d12.sock --remote-env REMOTE_CONTAINERS=true --mount-workspace-git-root --terminal-columns 311 --terminal-rows 16 --dotfiles-target-path ~/dotfiles
[2026-04-21T06:58:59.190Z] Exit code 1
[2026-04-21T06:58:59.192Z] Command failed: /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) /Users/dejhbk0l/.vscode/extensions/ms-vscode-remote.remote-containers-0.454.0/dist/spec-node/devContainersSpecCLI.js run-user-commands --user-data-folder /Users/dejhbk0l/Library/Application Support/Code/User/globalStorage/ms-vscode-remote.remote-containers/data --container-session-data-folder /tmp/devcontainers-fab3de7f-06fb-4a1c-862b-0d779dd34aee1776754476846 --workspace-folder /Users/dejhbk0l/GitRepos/liv3/aspire --id-label devcontainer.local_folder=/Users/dejhbk0l/GitRepos/liv3/aspire --id-label devcontainer.config_file=/Users/dejhbk0l/GitRepos/liv3/aspire/.devcontainer/devcontainer.json --container-id 0a780387687938185d38796158267408401531cfa680e80b898483e56e3be3ed --log-level debug --log-format json --config /Users/dejhbk0l/GitRepos/liv3/aspire/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --skip-non-blocking-commands true --prebuild false --stop-for-personalization true --remote-env REMOTE_CONTAINERS_IPC=/tmp/vscode-remote-containers-ipc-f434040b-ecc6-46e6-88a3-8e7aee2a6d12.sock --remote-env SSH_AUTH_SOCK=/tmp/vscode-ssh-auth-f434040b-ecc6-46e6-88a3-8e7aee2a6d12.sock --remote-env REMOTE_CONTAINERS=true --mount-workspace-git-root --terminal-columns 311 --terminal-rows 16 --dotfiles-target-path ~/dotfiles
[2026-04-21T06:58:59.192Z] Exit code 1

Maybe someone else (able to run tests) could fix them if they are quick ones? I opened a bug ticket #16354 to possibly be able to work on Aspire at some point in time. But right now, even easy things just take forever due to not being able to compile and test, sorry. I gave edit permission to maintainers.

Still not able to compile locally with macOS
@Falco20019
Copy link
Copy Markdown
Author

I hope to have fixed them by best guessing.

@Falco20019
Copy link
Copy Markdown
Author

Any update? It's been another 2 weeks without feedback :( As @joperezr mentioned, it should be nearly finished.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add IResourceWithServiceDiscovery to ContainerResource

5 participants