This sample demonstrates how to create custom commands in .NET Aspire that can dynamically pass arguments to resources using the new Interaction Service and Resource Command Service features introduced in .NET Aspire 9.4.
Screen.Recording.2025-08-07.at.9.07.57.AM.mov
This addresses the common need to:
- Run console applications with different command-line arguments from the Aspire dashboard
- Prompt users for input before starting a resource
- Dynamically configure resources based on user interaction
Common use cases include:
- Database migrations with different parameters
- Test runners with different filters
- Data seeding with various dataset sizes
The sample includes:
- MyApp - A simple console application that prints its command-line arguments
- AppHost - Configures the MyApp resource with:
WithExplicitStart()- Prevents automatic startupWithArgs()- Dynamically sets arguments based on user inputWithCommand()- Creates a custom "Run with args" command
When you click the "Run with args" command in the Aspire dashboard:
- A prompt appears asking for command-line arguments
- The arguments are parsed and stored
- The resource is started (or restarted) with the new arguments
- Run
aspire run - Open the Aspire dashboard
- Find the "myapp" resource and click the "Run with args" command (play icon)
- Enter some arguments in the prompt (e.g.,
--migrate --verbose) - The console app will start and display the provided arguments
This sample was created in response to dotnet/aspire#8502, which explored various approaches for dynamic resource configuration before the official Interaction Service was available.