Skip to content

aspire exec command

This article applies to: ✔️ Aspire CLI 9.4.0 and later versions.

aspire exec - Run an Aspire AppHost to execute a command against the resource.

Aspire CLI
aspire exec [options] [[--] <additional arguments>...]

The aspire exec command runs a command in the context of one of the resources defined in the AppHost.

You must specify either the --resource or the --start-resource option, and you must provide parameters with the -- option.

The Aspire CLI uses the following logic, in order, to determine which AppHost project to process:

  • The --project option.

    This option specifies the path to a project to process.

  • The .aspire/settings.json config file.

    If the config file path exists in the current directory, it’s used. If not, the CLI walks up the directory structure looking for the config file. If it finds a config file, it reads the appHostPath setting value as the project to process.

  • Searches the current directory and subdirectories.

    Starting in the current directory, the CLI gathers all AppHost projects from that directory and below. If a single project is discovered, it’s automatically selected. If multiple projects are discovered, they’re printed to the terminal for the user to manually select one of the projects.

    Once a project is selected, either automatically or manually, the path to the project is stored in the .aspire/settings.json config file.

The following options are available:

  • --

    Delimits arguments to aspire exec from arguments for the resource. All arguments after this delimiter are passed to the resource.

  • --project

    The path to the Aspire AppHost project file.

  • -r, --resource

    The name of the target resource to execute the command against.

  • -s, --start-resource

    The name of the target resource to start and execute the command against.

  • -?, -h, --help

    Prints help and usage documentation for the available commands and options.

  • -d, --debug

    Enable debug logging to the console, which prints detailed information about what .NET Aspire CLI is doing when a command is run.

  • --wait-for-debugger

    Wait for a debugger to attach before running a command.

  • Builds and runs the AppHost project, then sends the command migrate to the database1 resource:

    Aspire CLI
    aspire exec --resource database1 -- migrate
Ask & Answer Collaborate Community Discuss Watch