Share via


ProjectResourceBuilderExtensions.AddProject Method

Definition

Overloads

AddProject(IDistributedApplicationBuilder, String, String)

Adds a .NET project to the application model.

AddProject(IDistributedApplicationBuilder, String, String, Action<ProjectResourceOptions>)

Adds a .NET project to the application model.

AddProject(IDistributedApplicationBuilder, String, String, String)

Adds a .NET project to the application model.

AddProject<TProject>(IDistributedApplicationBuilder, String)

Adds a .NET project to the application model.

AddProject<TProject>(IDistributedApplicationBuilder, String, Action<ProjectResourceOptions>)

Adds a .NET project to the application model.

AddProject<TProject>(IDistributedApplicationBuilder, String, String)

Adds a .NET project to the application model. By default, this will exist in a Projects namespace. e.g. Projects.MyProject. If the project is not in a Projects namespace, make sure a project reference is added from the AppHost project to the target project.

AddProject(IDistributedApplicationBuilder, String, String)

Source:
ProjectResourceBuilderExtensions.cs

Adds a .NET project to the application model.

public static Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.ProjectResource> AddProject (this Aspire.Hosting.IDistributedApplicationBuilder builder, string name, string projectPath);
static member AddProject : Aspire.Hosting.IDistributedApplicationBuilder * string * string -> Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.ProjectResource>
<Extension()>
Public Function AddProject (builder As IDistributedApplicationBuilder, name As String, projectPath As String) As IResourceBuilder(Of ProjectResource)

Parameters

name
String

The name of the resource. This name will be used for service discovery when referenced in a dependency.

projectPath
String

The path to the project file.

Returns

A reference to the IResourceBuilder<T>.

Examples

Add a project to the app model via a project path.

var builder = DistributedApplication.CreateBuilder(args);

builder.AddProject("inventoryservice", @"..\InventoryService\InventoryService.csproj");

builder.Build().Run();

Remarks

This overload of the AddProject(IDistributedApplicationBuilder, String, String) method adds a project to the application model using a path to the project file. This allows for projects to be referenced that may not be part of the same solution. If the project path is not an absolute path then it will be computed relative to the app host directory.

Applies to

AddProject(IDistributedApplicationBuilder, String, String, Action<ProjectResourceOptions>)

Source:
ProjectResourceBuilderExtensions.cs

Adds a .NET project to the application model.

public static Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.ProjectResource> AddProject (this Aspire.Hosting.IDistributedApplicationBuilder builder, string name, string projectPath, Action<Aspire.Hosting.ProjectResourceOptions> configure);
static member AddProject : Aspire.Hosting.IDistributedApplicationBuilder * string * string * Action<Aspire.Hosting.ProjectResourceOptions> -> Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.ProjectResource>
<Extension()>
Public Function AddProject (builder As IDistributedApplicationBuilder, name As String, projectPath As String, configure As Action(Of ProjectResourceOptions)) As IResourceBuilder(Of ProjectResource)

Parameters

name
String

The name of the resource. This name will be used for service discovery when referenced in a dependency.

projectPath
String

The path to the project file.

configure
Action<ProjectResourceOptions>

A callback to configure the project resource options.

Returns

A reference to the IResourceBuilder<T>.

Examples

Add a project to the app model via a project path.

var builder = DistributedApplication.CreateBuilder(args);

builder.AddProject("inventoryservice", @"..\InventoryService\InventoryService.csproj", options => { options.LaunchProfileName = "otherLaunchProfile"; });

builder.Build().Run();

Remarks

This overload of the AddProject(IDistributedApplicationBuilder, String, String) method adds a project to the application model using a path to the project file. This allows for projects to be referenced that may not be part of the same solution. If the project path is not an absolute path then it will be computed relative to the app host directory.

Applies to

AddProject(IDistributedApplicationBuilder, String, String, String)

Source:
ProjectResourceBuilderExtensions.cs

Adds a .NET project to the application model.

public static Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.ProjectResource> AddProject (this Aspire.Hosting.IDistributedApplicationBuilder builder, string name, string projectPath, string? launchProfileName);
static member AddProject : Aspire.Hosting.IDistributedApplicationBuilder * string * string * string -> Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.ProjectResource>
<Extension()>
Public Function AddProject (builder As IDistributedApplicationBuilder, name As String, projectPath As String, launchProfileName As String) As IResourceBuilder(Of ProjectResource)

Parameters

name
String

The name of the resource. This name will be used for service discovery when referenced in a dependency.

projectPath
String

The path to the project file.

launchProfileName
String

The launch profile to use. If null then no launch profile will be used.

Returns

A reference to the IResourceBuilder<T>.

Examples

Add a project to the app model via a project path.

var builder = DistributedApplication.CreateBuilder(args);

builder.AddProject("inventoryservice", @"..\InventoryService\InventoryService.csproj", launchProfileName: "otherLaunchProfile");

builder.Build().Run();

Remarks

This overload of the AddProject(IDistributedApplicationBuilder, String, String) method adds a project to the application model using a path to the project file. This allows for projects to be referenced that may not be part of the same solution. If the project path is not an absolute path then it will be computed relative to the app host directory.

Applies to

AddProject<TProject>(IDistributedApplicationBuilder, String)

Source:
ProjectResourceBuilderExtensions.cs

Adds a .NET project to the application model.

public static Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.ProjectResource> AddProject<TProject> (this Aspire.Hosting.IDistributedApplicationBuilder builder, string name) where TProject : Aspire.Hosting.IProjectMetadata, new();
static member AddProject : Aspire.Hosting.IDistributedApplicationBuilder * string -> Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.ProjectResource> (requires 'Project :> Aspire.Hosting.IProjectMetadata and 'Project : (new : unit -> 'Project))
<Extension()>
Public Function AddProject(Of TProject As {IProjectMetadataNew}) (builder As IDistributedApplicationBuilder, name As String) As IResourceBuilder(Of ProjectResource)

Type Parameters

TProject

A type that represents the project reference.

Parameters

name
String

The name of the resource. This name will be used for service discovery when referenced in a dependency.

Returns

A reference to the IResourceBuilder<T>.

Examples

Example of adding a project to the application model.

var builder = DistributedApplication.CreateBuilder(args);

builder.AddProject<Projects.InventoryService>("inventoryservice");

builder.Build().Run();

Remarks

This overload of the AddProject<TProject>(IDistributedApplicationBuilder, String) method takes a TProject type parameter. The TProject type parameter is constrained to types that implement the IProjectMetadata interface.

Classes that implement the IProjectMetadata interface are generated when a .NET project is added as a reference to the app host project. The generated class contains a property that returns the path to the referenced project file. Using this path .NET Aspire parses the launchSettings.json file to determine which launch profile to use when running the project, and what endpoint configuration to automatically generate.

The name of the automatically generated project metadata type is a normalized version of the project name. Periods, dashes, and spaces in project names are converted to underscores. This normalization may lead to naming conflicts. If a conflict occurs the <ProjectReference /> that references the project can have a AspireProjectMetadataTypeName="..." attribute added to override the name.

Note that endpoints coming from the Kestrel configuration are automatically added to the project. The Kestrel Url and Protocols are used to build the equivalent EndpointAnnotation.

Applies to

AddProject<TProject>(IDistributedApplicationBuilder, String, Action<ProjectResourceOptions>)

Source:
ProjectResourceBuilderExtensions.cs

Adds a .NET project to the application model.

public static Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.ProjectResource> AddProject<TProject> (this Aspire.Hosting.IDistributedApplicationBuilder builder, string name, Action<Aspire.Hosting.ProjectResourceOptions> configure) where TProject : Aspire.Hosting.IProjectMetadata, new();
static member AddProject : Aspire.Hosting.IDistributedApplicationBuilder * string * Action<Aspire.Hosting.ProjectResourceOptions> -> Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.ProjectResource> (requires 'Project :> Aspire.Hosting.IProjectMetadata and 'Project : (new : unit -> 'Project))
<Extension()>
Public Function AddProject(Of TProject As {IProjectMetadataNew}) (builder As IDistributedApplicationBuilder, name As String, configure As Action(Of ProjectResourceOptions)) As IResourceBuilder(Of ProjectResource)

Type Parameters

TProject

A type that represents the project reference.

Parameters

name
String

The name of the resource. This name will be used for service discovery when referenced in a dependency.

configure
Action<ProjectResourceOptions>

A callback to configure the project resource options.

Returns

A reference to the IResourceBuilder<T>.

Examples

Example of adding a project to the application model.

var builder = DistributedApplication.CreateBuilder(args);

builder.AddProject<Projects.InventoryService>("inventoryservice", options => { options.LaunchProfileName = "otherLaunchProfile"; });

builder.Build().Run();

Remarks

This overload of the AddProject<TProject>(IDistributedApplicationBuilder, String) method takes a TProject type parameter. The TProject type parameter is constrained to types that implement the IProjectMetadata interface.

Classes that implement the IProjectMetadata interface are generated when a .NET project is added as a reference to the app host project. The generated class contains a property that returns the path to the referenced project file. Using this path .NET Aspire parses the launchSettings.json file to determine which launch profile to use when running the project, and what endpoint configuration to automatically generate.

The name of the automatically generated project metadata type is a normalized version of the project name. Periods, dashes, and spaces in project names are converted to underscores. This normalization may lead to naming conflicts. If a conflict occurs the <ProjectReference /> that references the project can have a AspireProjectMetadataTypeName="..." attribute added to override the name.

Applies to

AddProject<TProject>(IDistributedApplicationBuilder, String, String)

Source:
ProjectResourceBuilderExtensions.cs

Adds a .NET project to the application model. By default, this will exist in a Projects namespace. e.g. Projects.MyProject. If the project is not in a Projects namespace, make sure a project reference is added from the AppHost project to the target project.

public static Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.ProjectResource> AddProject<TProject> (this Aspire.Hosting.IDistributedApplicationBuilder builder, string name, string? launchProfileName) where TProject : Aspire.Hosting.IProjectMetadata, new();
static member AddProject : Aspire.Hosting.IDistributedApplicationBuilder * string * string -> Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.ProjectResource> (requires 'Project :> Aspire.Hosting.IProjectMetadata and 'Project : (new : unit -> 'Project))
<Extension()>
Public Function AddProject(Of TProject As {IProjectMetadataNew}) (builder As IDistributedApplicationBuilder, name As String, launchProfileName As String) As IResourceBuilder(Of ProjectResource)

Type Parameters

TProject

A type that represents the project reference.

Parameters

name
String

The name of the resource. This name will be used for service discovery when referenced in a dependency.

launchProfileName
String

The launch profile to use. If null then no launch profile will be used.

Returns

A reference to the IResourceBuilder<T>.

Examples

Example of adding a project to the application model.

var builder = DistributedApplication.CreateBuilder(args);

builder.AddProject<Projects.InventoryService>("inventoryservice", launchProfileName: "otherLaunchProfile");

builder.Build().Run();

Remarks

This overload of the AddProject<TProject>(IDistributedApplicationBuilder, String) method takes a TProject type parameter. The TProject type parameter is constrained to types that implement the IProjectMetadata interface.

Classes that implement the IProjectMetadata interface are generated when a .NET project is added as a reference to the app host project. The generated class contains a property that returns the path to the referenced project file. Using this path .NET Aspire parses the launchSettings.json file to determine which launch profile to use when running the project, and what endpoint configuration to automatically generate.

The name of the automatically generated project metadata type is a normalized version of the project name. Periods, dashes, and spaces in project names are converted to underscores. This normalization may lead to naming conflicts. If a conflict occurs the <ProjectReference /> that references the project can have a AspireProjectMetadataTypeName="..." attribute added to override the name.

Applies to