Skip to content

Commit 7d37af5

Browse files
CopilotIEvangelist
andauthored
Add AddCSharpApp and CSharpAppResource documentation to app-host-overview.md (#5318)
* Initial plan * Add AddCSharpApp and CSharpAppResource documentation to app-host-overview.md Co-authored-by: IEvangelist <7679720+IEvangelist@users.noreply.github.com> * Apply suggestions from code review * Update docs/fundamentals/app-host-overview.md --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: IEvangelist <7679720+IEvangelist@users.noreply.github.com> Co-authored-by: David Pine <david.pine@microsoft.com>
1 parent 1eb92d1 commit 7d37af5

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

docs/fundamentals/app-host-overview.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,16 @@ Aspire projects are made up of a set of resources. The primary base resource typ
130130
| Method | Resource type | Description |
131131
|--|--|--|
132132
| <xref:Aspire.Hosting.ProjectResourceBuilderExtensions.AddProject%2A> | <xref:Aspire.Hosting.ApplicationModel.ProjectResource> | A .NET project, for example, an ASP.NET Core web app. |
133+
| `AddCSharpApp` | `CSharpAppResource` | A C# project or file-based app, for example, a _*.cs_ file, _*.csproj_ file, or project directory. |
133134
| <xref:Aspire.Hosting.ContainerResourceBuilderExtensions.AddContainer%2A> | <xref:Aspire.Hosting.ApplicationModel.ContainerResource> | A container image, such as a Docker image. |
134135
| <xref:Aspire.Hosting.ExecutableResourceBuilderExtensions.AddExecutable%2A> | <xref:Aspire.Hosting.ApplicationModel.ExecutableResource> | An executable file, such as a [Node.js app](../get-started/build-aspire-apps-with-nodejs.md). |
135136
| <xref:Aspire.Hosting.ParameterResourceBuilderExtensions.AddParameter%2A> | <xref:Aspire.Hosting.ApplicationModel.ParameterResource> | A parameter resource that can be used to [express external parameters](external-parameters.md). |
136137

137-
Project resources represent .NET projects that are part of the app model. When you add a project reference to the AppHost project, the Aspire SDK generates a type in the `Projects` namespace for each referenced project. For more information, see [Aspire SDK: Project references](dotnet-aspire-sdk.md#project-references).
138+
<!-- TODO: add when xref is ready.
139+
| <xref:Aspire.Hosting.ProjectResourceBuilderExtensions.AddCSharpApp%2A> | <xref:Aspire.Hosting.ApplicationModel.CSharpAppResource> | A C# project or file-based app, for example, a .cs file, .csproj file, or project directory. |
140+
-->
141+
142+
Project resources represent .NET projects that are part of the app model. When you add a project reference to the AppHost project, the Aspire SDK generates a type in the `Projects` namespace for each referenced project. For more information, see [Aspire SDK: Project references](dotnet-aspire-sdk.md#project-references). Alternatively, you can add C# projects or file-based apps without a project reference using the `AddCSharpApp` method.
138143

139144
To add a project to the app model, use the <xref:Aspire.Hosting.ProjectResourceBuilderExtensions.AddProject%2A> method:
140145

@@ -157,6 +162,25 @@ var apiservice = builder.AddProject<Projects.AspireApp_ApiService>("apiservice")
157162

158163
The preceding code adds three replicas of the "apiservice" project resource to the app model. For more information, see [Aspire dashboard: Resource replicas](dashboard/explore.md#resource-replicas).
159164

165+
C# app resources represent C# projects or file-based apps that are part of the app model. Unlike <xref:Aspire.Hosting.ProjectResourceBuilderExtensions.AddProject%2A>, which requires a project reference, the `AddCSharpApp` method can add C# projects or file-based apps using a path to a _*.cs_ file, _*.csproj_ file, or project directory. This is useful for adding file-based apps introduced in .NET 10 or for including projects without adding a project reference to the AppHost.
166+
167+
To add a C# app to the app model, use the `AddCSharpApp` method:
168+
169+
```csharp
170+
var builder = DistributedApplication.CreateBuilder(args);
171+
172+
// Adds a file-based C# app "inventoryservice" from a .cs file.
173+
var inventoryService = builder.AddCSharpApp("inventoryservice", @"..\InventoryService.cs");
174+
175+
// Adds a C# project "catalogservice" from a project directory.
176+
var catalogService = builder.AddCSharpApp("catalogservice", @"..\CatalogService");
177+
```
178+
179+
The `AddCSharpApp` method supports the same configuration options as <xref:Aspire.Hosting.ProjectResourceBuilderExtensions.AddProject%2A>, including replicas, environment variables, and resource dependencies.
180+
181+
> [!NOTE]
182+
> The `AddCSharpApp` method is marked as experimental and requires .NET 10 SDK for file-based C# app support. For more information on file-based apps, see the [What's new in Aspire 9.5](../whats-new/dotnet-aspire-9.5.md#file-based-apphost-support-preview) documentation.
183+
160184
## Reference resources
161185

162186
A reference represents a dependency between resources. For example, you can probably imagine a scenario where a web frontend depends on a Redis cache. Consider the following example AppHost `Program` C# code:

0 commit comments

Comments
 (0)