# Set up .NET / C# apps in the AppHost

<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.
:::

If your C# AppHost needs to reference the resource type directly — for example, to declare a strongly typed variable or a method parameter — 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();
```

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**.

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

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

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

```typescript title="apphost.mts"
const builder = await createBuilder();

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

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

## Configure options

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

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

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

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

```typescript title="apphost.mts"
const builder = await createBuilder();

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

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

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.

## Publishing

Automatic project publishing for `DotnetProjectResource` isn't currently supported. A plain
`DotnetProjectResource` causes `aspire publish` and `aspire deploy` to fail with an actionable error
instead of emitting an `executable.v0` manifest containing machine-local paths.

Use one of these alternatives:

- Use `AddProject<TProject>(...)` for a project referenced by a C# AppHost.
- Use `AddCSharpApp(...)` / `addCSharpApp(...)` for a path-based project or file-based app that
  should use standard .NET project publishing.
- Call `PublishAsDockerFile(...)` / `publishAsDockerFile(...)` to configure container publishing
  explicitly.
- Call `ExcludeFromManifest()` / `excludeFromManifest()` when the resource is intentionally
  available only during local orchestration.

## 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)