Fusonic.Extensions.Aspire.Hosting
11.0.0
Prefix Reserved
dotnet add package Fusonic.Extensions.Aspire.Hosting --version 11.0.0
NuGet\Install-Package Fusonic.Extensions.Aspire.Hosting -Version 11.0.0
<PackageReference Include="Fusonic.Extensions.Aspire.Hosting" Version="11.0.0" />
<PackageVersion Include="Fusonic.Extensions.Aspire.Hosting" Version="11.0.0" />
<PackageReference Include="Fusonic.Extensions.Aspire.Hosting" />
paket add Fusonic.Extensions.Aspire.Hosting --version 11.0.0
#r "nuget: Fusonic.Extensions.Aspire.Hosting, 11.0.0"
#:package Fusonic.Extensions.Aspire.Hosting@11.0.0
#addin nuget:?package=Fusonic.Extensions.Aspire.Hosting&version=11.0.0
#tool nuget:?package=Fusonic.Extensions.Aspire.Hosting&version=11.0.0
Aspire Hosting
Package: Fusonic.Extensions.Aspire.Hosting (reference it in the AppHost project)
Extensions for the Aspire AppHost. Tested with Aspire 13.6.
The extension methods are in the namespace Aspire.Hosting, like Aspire's own, so they are available in the AppHost without a using. ProtectedSecretsOptions is in Fusonic.Extensions.Aspire.Hosting.
Compose stack
Aspire's containers show up in Docker Desktop as a flat list, mixed with everything else running on the machine. UseComposeStack labels them like Docker Compose does, so they are grouped as one stack:
var builder = DistributedApplication.CreateBuilder(args);
builder.UseComposeStack(); // stack "myapp" for MyApp.AppHost
var postgres = builder.AddPostgres("db")
.WithPgAdmin() // child resources are part of the stack, too
.WithComposeService("postgres"); // optional: service name other than the resource name
builder.AddContainer("mailpit", "axllent/mailpit")
.WithoutComposeStack(); // optional: leave a container out
- The stack name defaults to the AppHost's name without
.AppHost; pass one to override it:UseComposeStack("my-stack"). - Names are normalized to what Compose allows: lowercase letters, digits,
-and_. Other characters become-, leading and trailing-/_are trimmed. A name without any letter or digit throws anArgumentException. - Only in run mode;
aspire publishandaspire deployare not affected. - Changing the labels changes the configuration of a persistent container (
ContainerLifetime.Persistent), so Aspire recreates it once. Its volumes stay.
Protected secrets
When a parameter is entered in the Aspire dashboard and saved, Aspire writes it to the AppHost's user secrets: a plaintext secrets.json in the user profile. UseProtectedSecrets keeps these values in the operating system's secret store for the current user instead:
var builder = DistributedApplication.CreateBuilder(args);
builder.UseProtectedSecrets();
var apiKey = builder.AddParameter("api-key", secret: true); // entered in the dashboard as usual
- Stored secrets are loaded right after the user secrets, so a stale value in
secrets.jsondoesn't win, but environment variables and command line arguments still do. If the AppHost has no user secrets configured (noUserSecretsId), the stored secrets are added last and override environment variables and command line arguments as well. - Aspire's deployment state (
aspire publish/aspire deploy) stays in the user secrets. - Where no store is available (Linux without a keyring, e.g. headless or WSL), the AppHost logs a warning at startup and uses the plaintext user secrets as before.
Where the secrets are kept
| OS | Store |
|---|---|
| Windows | File encrypted with DPAPI for the current user, in %LOCALAPPDATA%\Fusonic.Extensions.Aspire |
| macOS | Keychain, service Fusonic.Extensions.Aspire |
| Linux | Secret Service via libsecret (e.g. GNOME Keyring), schema Fusonic.Extensions.Aspire.secrets |
The AppHost's secrets are identified by its UserSecretsId (or its name, if it has none). Both can be changed:
builder.UseProtectedSecrets(options =>
{
options.Name = "my-app";
options.Directory = "/some/where"; // the encrypted file on Windows
});
Uses the cache storage of Microsoft.Identity.Client.Extensions.Msal, the maintained cross-platform wrapper around these stores.
Limitations
- Generated parameter defaults (e.g. a password Aspire generates for
AddPostgreswithout one) are still saved to the plaintext user secrets: Aspire saves them throughIDistributedApplicationBuilder.UserSecretsManager, which can't be replaced. Set such parameters explicitly (AddParameter(..., secret: true)) to keep them in the store. - Values already in
secrets.jsonstay there. Remove them by hand (dotnet user-secrets remove <key>) after entering them again in the dashboard. - Builds on Aspire's experimental
IUserSecretsManager(ASPIREUSERSECRETS001). A newer Aspire version may need a new version of this package.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Aspire.Hosting (>= 17.0.0)
- Microsoft.Extensions.Configuration (>= 11.0.0)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 11.0.0)
- Microsoft.Extensions.Configuration.FileExtensions (>= 11.0.0)
- Microsoft.Extensions.Configuration.Json (>= 11.0.0)
- Microsoft.Extensions.Configuration.UserSecrets (>= 11.0.0)
- Microsoft.Extensions.DependencyInjection (>= 11.0.0)
- Microsoft.Extensions.Http (>= 11.0.0)
- Microsoft.Extensions.Logging.Console (>= 11.0.0)
- Microsoft.Identity.Client.Extensions.Msal (>= 4.92.0)
- Newtonsoft.Json (>= 13.0.4)
- OpenTelemetry.Api (>= 1.21.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.