Aspire

WPF and Windows Forms with Aspire

.NET logo

WPF (Windows Presentation Foundation) and Windows Forms are .NET desktop UI frameworks for building Windows applications. Because they are standard .NET projects, you can register them in an Aspire AppHost alongside your backend services with the same AddDotnetProjectaddDotnetProjectAddDotnetProject API you use for web and worker services. Aspire then starts and monitors the desktop app as a local process resource when you run the AppHost during development.

Desktop projects use the .NET / C# app integration, so no desktop-specific package is required.

  1. Add the .NET hosting integration to your AppHost, if it isn’t already installed:

    Terminal
    aspire add Aspire.Hosting.Dotnet
  2. Register the project in your AppHost by path and wire up any service references it needs:

    apphost.mts
    import { createBuilder } from './.aspire/modules/aspire.mjs';
    const builder = await createBuilder();
    const api = await builder.addDotnetProject('api', '../ApiService/ApiService.csproj');
    await builder
    .addDotnetProject('desktop', '../MyWpfApp/MyWpfApp.csproj')
    .withReference(api)
    .waitFor(api);
    await builder.build().run();

    When you run the AppHost, the desktop application starts automatically as a process resource alongside all other registered services.

  3. Add service discovery to the desktop project so it can resolve Aspire-managed service addresses at runtime. Reference the Aspire.ServiceDefaults project (or install Microsoft.Extensions.ServiceDiscovery directly), then configure the generic host in your startup code.

    For WPF, override OnStartup in App.xaml.cs:

    App.xaml.cs (WPF)
    public partial class App : Application
    {
    public IServiceProvider Services { get; private set; } = default!;
    protected override void OnStartup(StartupEventArgs e)
    {
    base.OnStartup(e);
    var host = Host.CreateDefaultBuilder()
    .ConfigureServices(services =>
    {
    services.AddServiceDiscovery();
    services.AddHttpClient<ApiClient>(client =>
    {
    client.BaseAddress = new Uri("https+http://api");
    }).AddServiceDiscovery();
    })
    .Build();
    Services = host.Services;
    host.Start();
    }
    }

    For Windows Forms, configure the host in Program.cs:

    Program.cs (Windows Forms)
    var host = Host.CreateDefaultBuilder(args)
    .ConfigureServices(services =>
    {
    services.AddServiceDiscovery();
    services.AddHttpClient<ApiClient>(client =>
    {
    client.BaseAddress = new Uri("https+http://api");
    }).AddServiceDiscovery();
    services.AddTransient<MainForm>();
    })
    .Build();
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(host.Services.GetRequiredService<MainForm>());

A common pattern is to register the desktop app only during local development and skip it in CI or staging environments. Check the AppHost environment to add the resource conditionally:

apphost.mts
import { createBuilder } from './.aspire/modules/aspire.mjs';
const builder = await createBuilder();
const env = await builder.environment.get();
const postgres = await builder.addPostgres('postgres');
const db = await postgres.addDatabase('mydb');
const api = await builder
.addDotnetProject('api', '../ApiService/ApiService.csproj')
.withReference(db);
if (await env.isDevelopment()) {
await builder
.addDotnetProject('desktop', '../MyWpfApp/MyWpfApp.csproj')
.withReference(api)
.waitFor(api);
}
await builder.build().run();
  • Windows only: WPF and Windows Forms require Windows. On macOS or Linux, the desktop resource will fail to start because the .NET WPF/WinForms runtime is unavailable on those platforms.
  • No deployment support: aspire deploy does not produce deployment artifacts for desktop apps. They are treated as development-time resources only.
  • Dashboard lifecycle: Desktop apps start automatically when the AppHost runs. Use the dashboard’s Stop, Start, Restart, and Rebuild commands to control the desktop app process.
FeatureWPF / WinForms.NET MAUI
Aspire hosting packageAspire.Hosting.Dotnet (AddDotnetProject)Aspire.Hosting.Maui
Platform supportWindows onlyWindows, macOS, iOS, Android
Dev Tunnels supportNot applicableBuilt-in for iOS/Android
Production deployment with AspireNot supportedNot supported

For cross-platform desktop and mobile scenarios, consider .NET MAUI integration.