8000 [WIP] feat: aspire exec command support by DeagleGross · Pull Request #9842 · dotnet/aspire · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[WIP] feat: aspire exec command support #9842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

DeagleGross
Copy link
Member
@DeagleGross DeagleGross commented Jun 12, 2025

Note: work in progress

Description

The idea is to have a separate aspire exec cli command, which allows to execute a command against some resource. It is the first part of Entity Framework E2E scenario improvements.

Contract: aspire exec --resource <targetResource> --command <command>.
Parameters:

  • resource specifies which resource command should target. In case target resource is csproj, then in which working directory should command be executed.
  • command specifies which command to execute. In case of EF it can be dotnet ef migrations add Initial.

Implementation

Aspire exec does the following under the hood:

  1. parses the input from Aspire.cli side, and runs (in "run" mode) the AppHost with --operation exec argument. This is a new type of DistributedApplicationOperation.
  2. DistributedApplication starts normally, except it tries to find the target resource, and only starts it and its dependencies. Consider this apphost:
var miniPostgres = builder.AddPostgres("miniPostgres");
var postgres = builder.AddPostgres("postgres");

// target resource
var webAppProject = builder.AddProject<TestingAppHost1_MyWebApp>("mywebapp1")
    .WithReference(postgres);

var workerProject = builder.AddProject<TestingAppHost1_MyWorker>("myworker");

If "mywebapp1" is the target resource, then only "mywebapp1" and "postgres" will start (not "miniPostgres" or "myworker").

  1. As a AfterResourcesCreatedAsync lifecycle hook I've attached Aspire.Hosting.Exec.DefaultCommandExecutor - all it does it parses the command, and executes it against the target resource.

  2. Maybe we need to forcefully shutdown apphost here?

TODO

  • attach the IAppHostBackchannel to see the logs and status of execution
  • test e2e from Aspire.Cli
  • prettify code / catch exceptions etc

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?

Relates #9859

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0