Aspire

aspire secret command

aspire secret - Manage AppHost secrets.

Aspire CLI
aspire secret [command] [options]

The aspire secret command manages secrets for an Aspire AppHost project. Secrets provide a safe way to store sensitive configuration values—such as passwords, API keys, and connection strings—outside of your project files.

Aspire uses secrets to persist values that resources need across restarts, such as auto-generated passwords for database containers. When you add a persistent resource that requires a password, Aspire saves the generated password. On subsequent runs, the saved password is reused so that the resource retains its state.

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

  • The --apphost option.

    This option specifies the path to the Aspire AppHost project file to process.

  • The rooted aspire.config.json file.

    If the rooted config exists in the current directory, it’s used. If not, the CLI walks up the directory structure looking for it. If Aspire finds the rooted config, it uses the recorded AppHost information to determine which project to process. Legacy .aspire/settings.json files are still read during migration.

  • 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, Aspire records that selection in the rooted configuration so later commands can reuse it.

Each aspire secret subcommand accepts --environment (or -e) to select the AppHost environment whose secrets you manage. Environment names are case-insensitive, and the default is Development. Secrets for each environment are stored in a separate JSON file in your user profile:

Secrets file location
~/.aspire/secrets/<apphost-id>/<environment>.json

The <apphost-id> is the AppHost’s UserSecretsId when it has one; otherwise, Aspire derives an ID from the AppHost file path. Use aspire secret path to print the exact file for an environment.

When the AppHost runs, it loads the secrets file for its environment—for example, Development for aspire run, or Production for aspire publish, aspire deploy, and aspire do unless you pass a different --environment. Values that a deployment prompts for are saved to the same file. Secrets override appsettings.json values, while environment variables and command-line arguments still take precedence.

When a secrets file contains invalid JSON, commands that read or write secrets, such as aspire secret get and aspire secret set, fail with a nonzero exit code and report the affected file path, the line and byte position, and repair guidance. The file can be an environment store, a legacy user-secrets file being imported, or a source or destination of a migration. The malformed content is preserved; Aspire never discards or overwrites it. In JSON strings, escape a backslash as \\ (for example, server\\sql).

Fix the JSON in the file named in the diagnostic, then try again. Use aspire secret path to locate the environment-specific secrets store; it doesn’t locate legacy import files or migration sources.

The following options are available:

  • --apphost <apphost>

    The path to the Aspire AppHost project file.

  • -?, -h, --help

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

  • -l, --log-level <Critical|Debug|Error|Information|None|Trace|Warning>

    Set the minimum log level for console output. Use this option to increase diagnostics while troubleshooting or reduce output in scripted runs.

  • --non-interactive

    Run the command in non-interactive mode, disabling all interactive prompts and spinners.

  • --nologo

    Suppress the startup banner and telemetry notice.

  • --banner

    Display the animated Aspire CLI welcome banner.

  • --wait-for-debugger

    Wait for a debugger to attach before running a command.

The following commands are available:

CommandFunction
aspire secret set <key> <value>Set a secret value.
aspire secret get <key>Get a secret value.
aspire secret listList all secrets.
aspire secret delete <key>Delete a secret.
aspire secret pathShow the secrets file path.
  • Set a secret value for the current AppHost:

    Aspire CLI
    aspire secret set Parameters:postgres-password MySecretPassword123
  • Set a secret for the Production environment from an environment variable:

    Aspire CLI
    aspire secret set Parameters:postgres-password --environment Production --envvar POSTGRES_PASSWORD
  • List all secrets for a specific AppHost:

    Aspire CLI
    aspire secret list --apphost ./src/MyApp.AppHost/MyApp.AppHost.csproj
  • Get the value of a specific secret:

    Aspire CLI
    aspire secret get Parameters:postgres-password
  • Show the path to the secrets file:

    Aspire CLI
    aspire secret path