Skip to content

[New article]: Aspire Exec #4026

Open
Open
@DeagleGross

Description

@DeagleGross

Proposed topic or title

Aspire exec

Location in table of contents.

this is new CLI command. It allows to execute a command in the context of the aspire resource. It is a generic-purpose feature. There are no consequences of not knowing this, but it should simplify working with whatever commands people invoke.

Reason for the article

Notes: Is originally developed here. See this for demo and details: dotnet/aspire#10061.. Original PR was reverted and later merged as this one: dotnet/aspire#10240

Aspire exec is a new CLI command. It is a general purpose command which allows to execute command in the context of another resource.

Originally idea for aspire exec came up as an improvement in the flow for Entity Framework experience. Developers mostly use 2 commands there (see EF docs for commands here):

  1. dotnet ef migrations add init which adds a new migration to the source code (builds the csproj, investigates the DbContext and models, and generates the code
  2. dotnet ef database update which builds the csproj, somewhat runs it and connects to the database and executes the EF migration scripts.

But aspire exec is a general purpose thing now, and it allows to execute whatever user wants in the context of aspire resource. Lets see an example of apphost:

var db = builder.AddPostgres("db");
builder.AddProject<>("api").WithReference(db).WaitFor(db);

if you have such a definition, you can run aspire exec --resource api -- dotnet ef migrations add Init. It will run in the context of "api" resource and will execute whatever is after -- (or it supports even without this delimiter).

Running "in the context" means to run in the working directory of so-called "target" resource (in this case - api), and inheriting the configuration (like args, env variables, connection strings). In case of entity framework migrations the most important is that it will inherit the connection string of db and will be able to apply the migrations on the database.

Full options of aspire exec:

  • --resource <resourcename> specifies against which target resource to run the command. in other words in the context of which resource to run a command
  • --start-resource <resourcename> the same as --resource but also waits until target resource starts. I dont know if it will be the naming going forward, so maybe we can avoid documenting it or explicitly write "this can be changed in future"?
  • --project <pathtoapphost> as in other commands you can specify a path to apphost if not living in your current directory tree.

Article abstract

Not sure i understand the purpose of this section - maybe "Execution of custom commands in the context of Aspire resources without manual switching"?

Relevant searches

No response

Metadata

Metadata

Assignees

Labels

🗺️ reQUESTTriggers an issue to be imported into Quest.Pri1High priority, do before Pri2 and Pri3area-docsdoc-ideaIndicates issues that are suggestions for new topics [org][type][category]

Type

Projects

Status

🏗 In progress

Relationships

None yet

Development

No branches or pull requests

Issue actions