Legacy project resources
This page is a reference for AppHosts that still use the legacy ProjectResource model through AddProject, AddCSharpApp, or TypeScript addProject.
Add a legacy project resource
Section titled “Add a legacy project resource”A TypeScript AppHost passes the path to the .csproj file:
import { createBuilder } from './.aspire/modules/aspire.mjs';
const builder = await createBuilder();
const api = await builder.addProject("api", "../ApiService/ApiService.csproj");
await builder.build().run();A C# AppHost references the target project with a ProjectReference marked as an Aspire project resource:
<ItemGroup> <ProjectReference Include="..\ApiService\ApiService.csproj" IsAspireProjectResource="true" ReferenceOutputAssembly="false" /></ItemGroup>When the AppHost builds, Aspire generates a metadata type in the Projects namespace for each marked reference. AddProjectaddProjectAddProject uses that type to locate the project:
var builder = DistributedApplication.CreateBuilder(args);
var api = builder.AddProject<Projects.ApiService>("api");
builder.Build().Run();AddCSharpAppaddCSharpAppAddCSharpApp takes a path to a project, directory, or file-based .cs app instead and doesn’t need a ProjectReference:
var worker = builder.AddCSharpApp("worker", "../Worker/Worker.csproj");Legacy project resources support the same resource APIs as other Aspire resources, such as WithReference, WaitFor, endpoints, and environment variables. For guidance that applies to all .NET project resources, see:
- Launch profiles for profile selection and endpoints from launchSettings.json and Kestrel configuration.
- Inner-loop networking for ports, proxies, and replicas.
- Set up .NET / C# apps in the AppHost for endpoint filtering, coordinated builds, and publishing.
Select a launch profile
Section titled “Select a launch profile”Legacy APIs take the launch profile as a method argument rather than an options object:
await builder.addProject("inventoryservice", "../InventoryService/InventoryService.csproj", { launchProfileOrOptions: "https",});builder.AddProject<Projects.InventoryService>("inventoryservice", launchProfileName: "https");
// Run without a launch profilebuilder.AddProject<Projects.Worker>("worker", launchProfileName: null);
// Use Kestrel endpoints instead of launch profile endpointsbuilder.AddProject<Projects.Catalog>("catalog", configure: static project =>{ project.ExcludeLaunchProfile = true; project.ExcludeKestrelEndpoints = false;});AddDotnetProject exposes the same choices through launchProfileName, excludeLaunchProfile, and excludeKestrelEndpoints options. See Configure options.
Customize generated project types
Section titled “Customize generated project types”To rename a generated Projects.* type, for example when two projects have the same name, set AspireProjectMetadataTypeName on the ProjectReference. AddDotnetProject takes a path, so it doesn’t use generated types or this metadata.
For the full set of ProjectReference metadata, see Generated project metadata.