Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" Version="13.4.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.8" />
<ProjectReference Include="..\MetricsApp\MetricsApp.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" Version="13.4.0" />
<PackageReference Include="Aspire.Hosting.PostgreSQL" Version="13.4.0" />
<PackageReference Include="Aspire.Hosting.Redis" Version="13.4.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.8" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Aspire.Hosting.AppHost" Version="13.4.0" />
<PackageVersion Include="Aspire.Hosting.Azure" Version="13.4.0" />
<!-- Aspire Hosting -->
<PackageVersion Include="Aspire.Hosting.Azure.AppContainers" Version="13.4.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var builder = DistributedApplication.CreateBuilder(args);

builder.AddAzureContainerAppEnvironment("env");
var env = builder.AddAzureContainerAppEnvironment("env");

var storage = builder.AddAzureStorage("storage").RunAsEmulator()
.ConfigureInfrastructure((infrastructure) =>
Expand All @@ -24,7 +24,8 @@
var blobs = storage.AddBlobs("blobs");
var queues = storage.AddQueues("queues");

var functions = builder.AddAzureFunctionsProject<Projects.ImageGallery_Functions>("functions")
var functions = builder.AddAzureFunctionsProject("functions", "../ImageGallery.Functions/ImageGallery.Functions.csproj")
.WithComputeEnvironment(env)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

.WithReference(queues)
.WithReference(blobs)
.WaitFor(storage)
Expand All @@ -37,6 +38,7 @@
.WithUrlForEndpoint("http", u => u.DisplayText = "Functions App");

builder.AddProject<Projects.ImageGallery_FrontEnd>("frontend")
.WithComputeEnvironment(env)
.WithReference(queues)
.WithReference(blobs)
.WaitFor(functions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" />
<PackageReference Include="Aspire.Hosting.Azure" />
<PackageReference Include="Microsoft.Extensions.Hosting" />
<ProjectReference Include="..\ImageGallery.FrontEnd\ImageGallery.FrontEnd.csproj" />
Expand Down
23 changes: 14 additions & 9 deletions samples/aspire-with-javascript/AspireJavaScript.AppHost/AppHost.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
var builder = DistributedApplication.CreateBuilder(args);
#pragma warning disable ASPIREBROWSERLOGS001
#pragma warning disable ASPIREJAVASCRIPT001

var builder = DistributedApplication.CreateBuilder(args);

var weatherApi = builder.AddProject<Projects.AspireJavaScript_MinimalApi>("weatherapi")
.WithExternalHttpEndpoints();
Expand All @@ -9,7 +12,8 @@
.WaitFor(weatherApi)
.WithHttpEndpoint(env: "PORT")
.WithExternalHttpEndpoints()
.PublishAsDockerFile();
.WithBrowserLogs()
.PublishAsStaticWebsite("/api", weatherApi, options => options.OutputPath = "dist/weather/browser");

builder.AddJavaScriptApp("react", "../AspireJavaScript.React", runScriptName: "start")
.WithNpm(installCommand: "ci")
Expand All @@ -18,7 +22,8 @@
.WithEnvironment("BROWSER", "none") // Disable opening browser on npm start
.WithHttpEndpoint(env: "PORT")
.WithExternalHttpEndpoints()
.PublishAsDockerFile();
.WithBrowserLogs()
.PublishAsStaticWebsite("/api", weatherApi);

builder.AddJavaScriptApp("vue", "../AspireJavaScript.Vue")
.WithRunScript("start")
Expand All @@ -27,14 +32,14 @@
.WaitFor(weatherApi)
.WithHttpEndpoint(env: "PORT")
.WithExternalHttpEndpoints()
.PublishAsDockerFile();
.WithBrowserLogs()
.PublishAsStaticWebsite("/api", weatherApi);

var reactVite = builder.AddViteApp("reactvite", "../AspireJavaScript.Vite")
builder.AddViteApp("reactvite", "../AspireJavaScript.Vite")
.WithNpm(installCommand: "ci")
.WithReference(weatherApi)
.WithEnvironment("BROWSER", "none");

// Bundle the output of the Vite app into the wwwroot of the weather API
weatherApi.PublishWithContainerFiles(reactVite, "./wwwroot");
.WithEnvironment("BROWSER", "none")
.WithBrowserLogs()
.PublishAsStaticWebsite("/api", weatherApi);

builder.Build().Run();
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" Version="13.4.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.8" />
<ProjectReference Include="..\AspireJavaScript.MinimalApi\AspireJavaScript.MinimalApi.csproj" />
<PackageReference Include="Aspire.Hosting.Browsers" Version="13.4.0-preview.1.26281.18" />
<PackageReference Include="Aspire.Hosting.JavaScript" Version="13.4.0" />
</ItemGroup>

Expand Down
5 changes: 4 additions & 1 deletion samples/aspire-with-node/AspireWithNode.AppHost/AppHost.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var builder = DistributedApplication.CreateBuilder(args);
#pragma warning disable ASPIREBROWSERLOGS001

var builder = DistributedApplication.CreateBuilder(args);

var cache = builder.AddRedis("cache")
.WithRedisInsight();
Expand All @@ -12,6 +14,7 @@
.WithHttpEndpoint(port: 5223, env: "PORT")
.WithExternalHttpEndpoints()
.WithHttpHealthCheck("/health")
.WithBrowserLogs()
.WithReference(weatherapi).WaitFor(weatherapi)
.WithReference(cache).WaitFor(cache);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" Version="13.4.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.8" />
<ProjectReference Include="..\AspireWithNode.AspNetCoreApi\AspireWithNode.AspNetCoreApi.csproj" />
<PackageReference Include="Aspire.Hosting.Browsers" Version="13.4.0-preview.1.26281.18" />
<PackageReference Include="Aspire.Hosting.JavaScript" Version="13.4.0" />
<PackageReference Include="Aspire.Hosting.Redis" Version="13.4.0" />
</ItemGroup>
Expand Down
12 changes: 8 additions & 4 deletions samples/aspire-with-python/apphost.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#pragma warning disable ASPIREBROWSERLOGS001
#pragma warning disable ASPIREJAVASCRIPT001

#:sdk Aspire.AppHost.Sdk@13.4.0
#:package Aspire.Hosting.JavaScript@13.4.0
#:package Aspire.Hosting.Browsers@13.4.0-preview.1.26281.18
#:package Aspire.Hosting.Python@13.4.0
#:package Aspire.Hosting.Redis@13.4.0

Expand All @@ -14,10 +18,10 @@
.WaitFor(cache)
.WithHttpHealthCheck("/health");

var frontend = builder.AddViteApp("frontend", "./frontend")
builder.AddViteApp("frontend", "./frontend")
.WithReference(app)
.WaitFor(app);

app.PublishWithContainerFiles(frontend, "./static");
.WaitFor(app)
.WithBrowserLogs()
.PublishAsStaticWebsite("/api", app);

builder.Build().Run();
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" Version="13.4.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.8" />
<ProjectReference Include="..\ClientAppsIntegration.ApiService\ClientAppsIntegration.ApiService.csproj" />
<ProjectReference Include="..\ClientAppsIntegration.WinForms\ClientAppsIntegration.WinForms.csproj" />
Expand Down
22 changes: 22 additions & 0 deletions samples/custom-resources/CustomResources.AppHost/AppHost.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
using CustomResources.AppHost;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

var builder = DistributedApplication.CreateBuilder(args);

builder.AddTalkingClock("talking-clock");

builder.AddTestResource("test");

builder.OnBeforeStart(static (@event, cancellationToken) =>
{
var logger = @event.Services.GetRequiredService<ILoggerFactory>()
.CreateLogger("CustomResources.AppHost");

logger.LogInformation("Starting custom resources sample with {ResourceCount} resources.", @event.Model.Resources.Count);

return Task.CompletedTask;
});

builder.Eventing.Subscribe<AfterResourcesCreatedEvent>(static (@event, cancellationToken) =>
{
var logger = @event.Services.GetRequiredService<ILoggerFactory>()
.CreateLogger("CustomResources.AppHost");

logger.LogInformation("Custom resources sample created {ResourceCount} resources.", @event.Model.Resources.Count);

return Task.CompletedTask;
});

builder.Build().Run();
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<UserSecretsId>00d08ee4-b2e0-4d12-827c-d131fda1c6f6</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" Version="13.4.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.8" />
</ItemGroup>

Expand Down
19 changes: 19 additions & 0 deletions samples/custom-resources/CustomResources.AppHost/TestResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Globalization;
using System.Text.Json;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
Expand All @@ -23,6 +24,24 @@ public static IResourceBuilder<TestResource> AddTestResource(this IDistributedAp
new(CustomResourceKnownProperties.Source, "Custom")
]
})
.WithCommand(
name: "inspect",
displayName: "Inspect resource",
executeCommand: context =>
{
context.Logger.LogInformation("Inspect command executed for {ResourceName}.", context.ResourceName);

var result = JsonSerializer.Serialize(new
{
resource = context.ResourceName,
generatedAt = DateTimeOffset.UtcNow
});

return Task.FromResult(CommandResults.Success(
message: "Resource inspection generated.",
result: result,
resultFormat: CommandResultFormat.Json));
})
.ExcludeFromManifest();

rb.OnInitializeResource((resource, e, ct) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" Version="13.4.0" />
<PackageReference Include="Aspire.Hosting.MySql" Version="13.4.0" />
<PackageReference Include="Aspire.Hosting.PostgreSQL" Version="13.4.0" />
<PackageReference Include="Aspire.Hosting.SqlServer" Version="13.4.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" Version="13.4.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.8" />
<ProjectReference Include="..\DatabaseMigrations.ApiService\DatabaseMigrations.ApiService.csproj" />
<ProjectReference Include="..\DatabaseMigrations.MigrationService\DatabaseMigrations.MigrationService.csproj" />
Expand Down
8 changes: 6 additions & 2 deletions samples/health-checks-ui/HealthChecksUI.AppHost/AppHost.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
var builder = DistributedApplication.CreateBuilder(args);

builder.AddDockerComposeEnvironment("compose");
var compose = builder.AddDockerComposeEnvironment("compose");

var cache = builder.AddRedis("cache");
var cache = builder.AddRedis("cache")
.WithComputeEnvironment(compose);

var apiService = builder.AddProject<Projects.HealthChecksUI_ApiService>("apiservice")
.WithComputeEnvironment(compose)
.WithHttpHealthCheck("/health")
.WithHttpProbe(ProbeType.Liveness, "/alive")
.WithFriendlyUrls(displayText: "API");

var webFrontend = builder.AddProject<Projects.HealthChecksUI_Web>("webfrontend")
.WithComputeEnvironment(compose)
.WithReference(cache)
.WaitFor(cache)
.WithReference(apiService)
Expand All @@ -20,6 +23,7 @@
.WithExternalHttpEndpoints();

var healthChecksUI = builder.AddHealthChecksUI("healthchecksui")
.WithComputeEnvironment(compose)
.WithReference(apiService)
.WithReference(webFrontend)
.WithFriendlyUrls("HealthChecksUI Dashboard", "http")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" Version="13.4.0" />
<PackageReference Include="Aspire.Hosting.Docker" Version="13.4.0" />
<PackageReference Include="Aspire.Hosting.Redis" Version="13.4.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.8" />
Expand Down
9 changes: 5 additions & 4 deletions samples/image-gallery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ flowchart LR
**Publish Mode:**
```mermaid
flowchart LR
Browser --> API[C# API serving<br/>Vite build output<br/>'npm run build']
Browser --> Frontend[Static website serving<br/>Vite build output<br/>'npm run build']
Frontend -->|Proxy /api| API[C# API]
API --> Blobs[Azure Blob Storage]
API --> Queue[Azure Storage Queue]
API --> SQL[Azure SQL]
Expand Down Expand Up @@ -54,7 +55,7 @@ flowchart LR
- **Dual-Mode Resources**: Azurite/SQL Server containers locally, Azure services in production (`.RunAsEmulator()`, `.RunAsContainer()`)
- **Free Tier Deployment**: Azure SQL free tier with serverless auto-pause, Container Apps scale-to-zero
- **Managed Identity**: Password-less authentication to all Azure resources (Storage, SQL, Queues)
- **Polyglot Stack**: Vite+React frontend embedded in C# API container, SkiaSharp for image processing
- **Polyglot Stack**: Vite+React frontend published as a static website, SkiaSharp for image processing
- **OpenTelemetry**: Distributed tracing across upload → queue → worker pipeline

## Running Locally
Expand Down Expand Up @@ -194,9 +195,9 @@ else
}
```

**Container Files Publishing** - Embed Vite build output in API container:
**Static Website Publishing** - Publish the Vite app as a static website with API proxying:
```csharp
api.PublishWithContainerFiles(frontend, "wwwroot");
frontend.PublishAsStaticWebsite("/api", api);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we make this snippet copy/paste accurate? frontend is not declared in the AppHost anymore after this change, so I think either the snippet should show the chained call or capture var frontend = builder.AddViteApp(...) first.

```

## Performance & Cost Characteristics
Expand Down
18 changes: 11 additions & 7 deletions samples/image-gallery/apphost.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#pragma warning disable ASPIRECSHARPAPPS001
#pragma warning disable ASPIREAZURE002
#pragma warning disable ASPIREBROWSERLOGS001
#pragma warning disable ASPIREJAVASCRIPT001

#:sdk Aspire.AppHost.Sdk@13.4.0
#:package Aspire.Hosting.Azure.Storage@13.4.0
#:package Aspire.Hosting.Azure.Sql@13.4.0
#:package Aspire.Hosting.JavaScript@13.4.0
#:package Aspire.Hosting.Browsers@13.4.0-preview.1.26281.18
#:package Aspire.Hosting.Azure.AppContainers@13.4.0

using Aspire.Hosting.Azure;
Expand All @@ -13,7 +16,7 @@

var builder = DistributedApplication.CreateBuilder(args);

builder.AddAzureContainerAppEnvironment("env");
var env = builder.AddAzureContainerAppEnvironment("env");

// Storage: Use Azurite emulator in run mode, real Azure in publish mode
var storage = builder.AddAzureStorage("storage")
Expand All @@ -29,6 +32,7 @@

// API: Upload images, queue thumbnail jobs, serve metadata
var api = builder.AddCSharpApp("api", "./api")
.WithComputeEnvironment(env)
.WithHttpHealthCheck("/health")
.WithExternalHttpEndpoints()
.WaitFor(sql)
Expand Down Expand Up @@ -58,6 +62,7 @@
// Worker: Container Apps Job for queue-triggered thumbnail generation
// Event-driven: starts when messages arrive, exits within ~5 seconds when queue is empty
var worker = builder.AddCSharpApp("worker", "./worker")
.WithComputeEnvironment(env)
.WithReference(blobs)
.WithReference(queues)
.WithReference(sql)
Expand Down Expand Up @@ -99,13 +104,12 @@
}

// Frontend: Vite+React for upload and gallery UI
var frontend = builder.AddViteApp("frontend", "./frontend")
builder.AddViteApp("frontend", "./frontend")
.WithEndpoint("http", e => e.Port = 9080)
.WithReference(api)
.WithUrl("", "Image Gallery");

// Publish: Embed frontend build output in API container
api.PublishWithContainerFiles(frontend, "wwwroot");
.WithUrl("", "Image Gallery")
.WithBrowserLogs()
.WithComputeEnvironment(env)
.PublishAsStaticWebsite("/api", api);

builder.Build().Run();

Loading
Loading