Skip to content
Merged
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
14 changes: 14 additions & 0 deletions src/frontend/config/sidebar/integrations.topics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,20 @@ export const integrationTopics: StarlightSidebarTopicsUserConfig = {
},
],
},
{
label: '.NET / C#',
collapsed: true,
items: [
{
label: 'Get started',
slug: 'integrations/frameworks/dotnet/dotnet-get-started',
},
{
label: 'Set up .NET / C# apps in the AppHost',
slug: 'integrations/frameworks/dotnet/dotnet-host',
},
],
},
{
label: 'Go',
collapsed: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
title: Get started with the .NET / C# app integration
description: Understand how the Aspire Dotnet hosting integration runs C# projects and file-based apps by path from your AppHost and how to choose the right setup path.
---

import { LinkButton, Steps } from '@astrojs/starlight/components';
import ThemeImage from '@components/ThemeImage.astro';
import csharpIcon from '@assets/icons/csharp.svg';

<ThemeImage
light={csharpIcon}
dark={csharpIcon}
alt="C# logo"
width={100}
height={100}
zoomable={false}
classOverride="float-inline-left icon"
/>

The Aspire `Aspire.Hosting.Dotnet` integration lets you add C# projects and file-based C# apps to your AppHost **by path**, without referencing a project from the AppHost's own solution. It's the C# peer of the `Aspire.Hosting.Go`, `Aspire.Hosting.Python`, and `Aspire.Hosting.JavaScript` hosting integrations.

:::caution[Experimental]
`AddDotnetProject` / `addDotnetProject` is experimental and exposed under the `ASPIREDOTNETPROJECT001` diagnostic. Its API surface may change in future releases.
:::

## Why use the Dotnet hosting integration

Adding C# apps by path through `Aspire.Hosting.Dotnet` gives you:

- **Path-based orchestration for C#.** Model a C# project or a file-based `.cs` app in the AppHost the same way you'd model a Go, Python, or JavaScript app added by path, without adding the project to the AppHost's solution.
- **File-based app support.** Add a single `.cs` file-based app (requires .NET 10 or later) directly, matching the file-based apps experience for `dotnet run --file`.
- **Familiar launch and configuration behavior.** Endpoints, environment variables, and service discovery are configured from the project's `launchSettings.json` and Kestrel configuration, matching `AddProject<T>`.

## How the pieces fit together

The Dotnet integration is a **hosting integration**. You install it in the AppHost and use `AddDotnetProject` / `addDotnetProject` to add a C# project or file-based app resource by path.

<Steps>

1. ### Set up C# apps in the AppHost

Add the `Aspire.Hosting.Dotnet` hosting integration to your AppHost, then use `AddDotnetProject` / `addDotnetProject` to model a C# project or file-based app resource by path. The host reference covers package installation, path resolution, and launch behavior.

<LinkButton
variant="secondary"
iconPlacement="end"
icon="right-arrow"
href="/integrations/frameworks/dotnet/dotnet-host/"
>
Set up .NET / C# apps in the AppHost
</LinkButton>

</Steps>

## See also

- [.NET documentation](https://learn.microsoft.com/dotnet/)
- [.NET / C# AppHost setup reference](/integrations/frameworks/dotnet/dotnet-host/)
- [Aspire integrations overview](/integrations/overview/)
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
---
title: Set up .NET / C# apps in the AppHost
seoTitle: 'Set up .NET / C# apps in the Aspire AppHost: hosting integration'
description: Learn how to use the Aspire Dotnet hosting integration to add C# projects and file-based C# apps by path in an Aspire solution.
---

import { Tabs, TabItem } from '@astrojs/starlight/components';
import LearnMore from '@components/LearnMore.astro';
import ThemeImage from '@components/ThemeImage.astro';
import csharpIcon from '@assets/icons/csharp.svg';

<ThemeImage
light={csharpIcon}
dark={csharpIcon}
alt="C# logo"
width={100}
height={100}
zoomable={false}
classOverride="float-inline-left icon"
/>

This article is the reference for the Aspire Dotnet hosting integration. It enumerates the AppHost APIs — with examples for both `AppHost.cs` and `apphost.mts` — that you use to add C# projects and file-based C# apps **by path** in your [`AppHost`](/get-started/app-host/) project.

If you're new to the Dotnet integration, start with the [Get started with the .NET / C# app integration](/integrations/frameworks/dotnet/dotnet-get-started/) guide.

:::caution[Experimental]
`AddDotnetProject` / `addDotnetProject` is experimental and exposed under the `ASPIREDOTNETPROJECT001` diagnostic. Its API surface may change in future releases.
:::

:::note[Prerequisites]
The **.NET SDK** must be available on the `PATH` of the machine running the AppHost. File-based C# apps (`.cs`) require **.NET 10 or later**.
:::

## Installation

To start building an Aspire app that adds a C# project or file-based app by path, install the [📦 Aspire.Hosting.Dotnet](https://www.nuget.org/packages/Aspire.Hosting.Dotnet) NuGet package:

<Tabs syncKey="aspire-lang">
<TabItem id="csharp" label="C#">

```bash title="Terminal"
aspire add Aspire.Hosting.Dotnet
```

<LearnMore>
Learn more about [`aspire add`](/reference/cli/commands/aspire-add/) in the
command reference.
</LearnMore>

Or, choose a manual installation approach:

```csharp title="AppHost.cs"
#:package Aspire.Hosting.Dotnet@*
```

```xml title="AppHost.csproj"
<PackageReference Include="Aspire.Hosting.Dotnet" Version="*" />
```

</TabItem>
<TabItem id="typescript" label="TypeScript">

```bash title="Terminal"
aspire add Aspire.Hosting.Dotnet
```

<LearnMore>
Learn more about [`aspire add`](/reference/cli/commands/aspire-add/) in the
command reference.
</LearnMore>

This updates your `aspire.config.json` with the Dotnet hosting integration package:

```json title="aspire.config.json" ins={3}
{
"packages": {
"Aspire.Hosting.Dotnet": "13.5.0"
}
}
```

</TabItem>
</Tabs>

## Add a C# project or file-based app by path

Use `AddDotnetProject` / `addDotnetProject` to add a C# project or file-based app resource by path. The `path` argument can point at a project file (`.csproj`), a directory containing a single `.csproj`, or a file-based app (`.cs`). If the path isn't absolute, it's computed relative to the AppHost directory.

<Tabs syncKey='aspire-lang'>
<TabItem id='csharp' label='C#'>

```csharp title="AppHost.cs"
var builder = DistributedApplication.CreateBuilder(args);

var api = builder.AddDotnetProject("api", "../api/api.csproj")
.WithHttpEndpoint(port: 8080)
.WithExternalHttpEndpoints();

builder.Build().Run();
```

</TabItem>
<TabItem id='typescript' label='TypeScript'>

```typescript title="apphost.mts"
import { createBuilder } from './.aspire/modules/aspire.mjs';

const builder = await createBuilder();

const api = await builder.addDotnetProject('api', '../api/api.csproj');
await api.withHttpEndpoint({ port: 8080 });
await api.withExternalHttpEndpoints();

await builder.build().run();
```

</TabItem>
</Tabs>

The resource launches with `dotnet run --project <path>` for a project file, or `dotnet run --file <path>` for a file-based app. Endpoints, environment variables, and service discovery are configured from the project's `launchSettings.json` and Kestrel configuration, matching `AddProject<T>`.

## Add a file-based C# app

A file-based app is a single `.cs` file run directly with `dotnet run --file`, without a `.csproj`. File-based apps require **.NET 10 or later**.

<Tabs syncKey='aspire-lang'>
<TabItem id='csharp' label='C#'>

```csharp title="AppHost.cs"
var builder = DistributedApplication.CreateBuilder(args);

builder.AddDotnetProject("inventoryservice", @"..\InventoryService.cs");

builder.Build().Run();
```

</TabItem>
<TabItem id='typescript' label='TypeScript'>

```typescript title="apphost.mts"
import { createBuilder } from './.aspire/modules/aspire.mjs';

const builder = await createBuilder();

await builder.addDotnetProject('inventoryservice', '../InventoryService.cs');

await builder.build().run();
```

</TabItem>
</Tabs>

## Configure options

Pass a configuration action to set additional options such as the launch profile:

<Tabs syncKey='aspire-lang'>
<TabItem id='csharp' label='C#'>

```csharp title="AppHost.cs"
var builder = DistributedApplication.CreateBuilder(args);

builder.AddDotnetProject("inventoryservice", @"..\InventoryService.cs", o => o.LaunchProfileName = "https");

builder.Build().Run();
```

</TabItem>
<TabItem id='typescript' label='TypeScript'>

```typescript title="apphost.mts"
import { createBuilder } from './.aspire/modules/aspire.mjs';

const builder = await createBuilder();

await builder.addDotnetProject('inventoryservice', '../InventoryService.cs', {
launchProfileName: 'https',
});

await builder.build().run();
```

</TabItem>
</Tabs>

The resource is added as an [`ExecutableResource`](/app-host/executable-resources/) rather than a `ProjectResource`, so it doesn't need to be referenced from the AppHost's own solution. Before the resource starts, Aspire validates that the path resolves to a `.csproj` or `.cs` file (or a directory containing a single `.csproj`) and, for file-based apps, that the active .NET SDK version is 10 or later.

## See also

- [.NET documentation](https://learn.microsoft.com/dotnet/)
- [Get started with the .NET / C# app integration](/integrations/frameworks/dotnet/dotnet-get-started/)
- [Aspire integrations overview](/integrations/overview/)
- [Aspire GitHub repo](https://github.com/microsoft/aspire)
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ The sections below use the labels that are most helpful when you're trying to an
<Card title="C# and .NET apps">
Use Aspire with C# projects, file-based apps, and other .NET workloads.

Start with [C# file-based apps](/integrations/dotnet/csharp-file-based-apps/) or [Project resources](/integrations/dotnet/project-resources/).
Start with [C# file-based apps](/integrations/dotnet/csharp-file-based-apps/) or [Project resources](/integrations/dotnet/project-resources/). To add a C# project or file-based app **by path** without referencing it from the AppHost's solution, use the [.NET / C# integration](/integrations/frameworks/dotnet/dotnet-get-started/).
</Card>

<Card title="JavaScript and Node.js apps">
Expand Down
4 changes: 4 additions & 0 deletions src/frontend/src/data/integration-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@
"match": "Aspire.Hosting.Docker",
"href": "/integrations/compute/docker/"
},
{
"match": "Aspire.Hosting.Dotnet",
"href": "/integrations/frameworks/dotnet/dotnet-get-started/"
},
{
"match": "Aspire.Hosting.Elasticsearch",
"href": "/integrations/databases/elasticsearch/elasticsearch-get-started/"
Expand Down
Loading