Skip to content

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

@DeagleGross
Copy link
Member Author

dropped in favor of #10240

@DeagleGross DeagleGross closed this Jul 4, 2025
@DeagleGross DeagleGross deleted the dmkorolev/aspire-exec branch July 10, 2025 08:03
@github-actions github-actions bot locked and limited conversation to collaborators Aug 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant