Custom Resource Commands - Dynamic Command-Line Arguments #8502
BaconSoap
started this conversation in
Show and tell
Replies: 2 comments 2 replies
-
Beta Was this translation helpful? Give feedback.
0 replies
-
This would also be handy for running end-to-end tests from the Aspire dashboard where we could have custom commands that trigger different test filters. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Goal: add a custom resource command that conditionally sets a command-line argument before running the resource/executable.
this --migrate flag is set for a single run by the command

Using EF migrations in an Aspire world require some workarounds vs command-line tooling, with the most appealing & currently documented being a custom command-line app, managed via the dashboard.
With the new custom resource commands I wanted to add a single MyProject.Tools executable, with different in-UI commands for applying migrations, run certain seeding, etc. This was easy to achieve using a "set flag + run app" pair with a global bool:
from memory
but not very pleasant - requires multiple interactions and it's not clear what the current state is. By #6015 , there's not a built-in way that's exposed to end users.
The built-in commands (see here - very helpful for reference!) use ApplicationOrchestrator, which is internal - but with a simple signature, easy to get via reflection 😎.
Warning
This uses reflection and isn't very hardened - just sharing my workaround to what I suspect is a growing need + some thoughts on improvements.
Here's a gist that uses reflection to add a proxy class over ApplicationOrchestrator, with the
.Start()
method implemented (since that's all I needed). There are definitely better ways to do this, but with the baseline being "reflection of library's internal methods" I didn't put in too much effort. It's likely not very safe for long-running operations, and would need effort to prevent running multiple conflicting commands.To use:
builder.Services.AddApplicationOrchestratorProxy()
.WithArgs(c => /** conditionally call c.Args.Add() based on the flag or other logic **/)
.WithCommand()
to configure your custom command. This should set the global flag, resolve the proxy, start the app, and unset the flag when done..WithExplicitStart()
to prevent the app from running by default, if you want to require an explicit actionisHighlighted
, which moves the icon from the submenu to an (icon-only) option in the main bar - makes it one-click but requires a bit of duplication if you also want it in the list of text items.If successful, a new option will appear in your resource's section in the Aspire dashboard - both the main table, and in places like the log details toolbar. If configured as a highlighted option, it will be an icon next to the start/stop/logs icons.
Aspire team: in general, but especially with the EF migrations story strongly encouraging the "separate executable" scenarios, I feel it'd be helpful to have an official way to do one of:
A combo of 1 + 2 or 3 would solve this story in a fairly flexible way, without being overly tied to a specific resource type or encouraging loose global state. 2 or 3 alone would also work well but (unless I'm missing something) wouldn't feel as clean/safe for this use case.
I also played around with the app instead being a minimal server + HTTP commands, but didn't want to leave that running...
Please let me know if I missed an easier/safer option! And thanks for the tooling & platform, every update is easing modern dev pains.
Beta Was this translation helpful? Give feedback.
All reactions