Skip to content
DocsTry Aspire
DocsTry

DotnetProjectHostingExtensions Methods

ClassMethods2 members
Provides extension methods for adding C# projects and file-based C# apps (by path) to an Hosting.IDistributedApplicationBuilder.
AddDotnetProject(IDistributedApplicationBuilder, string, string)Section titled AddDotnetProject(IDistributedApplicationBuilder, string, string)extensionIResourceBuilder<DotnetProjectResource>
Adds a C# project or file-based app to the application model.
public static class DotnetProjectHostingExtensions
{
public static IResourceBuilder<DotnetProjectResource> AddDotnetProject(
this IDistributedApplicationBuilder builder,
string name,
string path)
{
// ...
}
}
builderIDistributedApplicationBuilderThe Hosting.IDistributedApplicationBuilder.
namestringThe name of the resource. This name will be used for service discovery when referenced in a dependency.
pathstringThe path to the file-based app file, project file, or project directory.
IResourceBuilder<DotnetProjectResource>A reference to the ApplicationModel.IResourceBuilder`1.

This overload of the DotnetProjectHostingExtensions.AddDotnetProject method adds a C# project or file-based app to the application model using a path to the file-based app .cs file, project file (.csproj), or project directory. If the path is not an absolute path then it will be computed relative to the AppHost directory.

Add a file-based app to the app model via a file path.
var builder = DistributedApplication.CreateBuilder(args);
builder.AddDotnetProject("inventoryservice", @"..\InventoryService.cs");
builder.Build().Run();
AddDotnetProject(IDistributedApplicationBuilder, string, string, Action<ProjectResourceOptions>)Section titled AddDotnetProject(IDistributedApplicationBuilder, string, string, Action<ProjectResourceOptions>)extensionIResourceBuilder<DotnetProjectResource>
Adds a C# project or file-based app to the application model.
public static class DotnetProjectHostingExtensions
{
public static IResourceBuilder<DotnetProjectResource> AddDotnetProject(
this IDistributedApplicationBuilder builder,
string name,
string path,
Action<ProjectResourceOptions> configure)
{
// ...
}
}
builderIDistributedApplicationBuilderThe Hosting.IDistributedApplicationBuilder.
namestringThe name of the resource. This name will be used for service discovery when referenced in a dependency.
pathstringThe path to the file-based app file, project file, or project directory.
configureAction<ProjectResourceOptions>An optional action to configure the C# app resource options.
IResourceBuilder<DotnetProjectResource>A reference to the ApplicationModel.IResourceBuilder`1.

This overload of the DotnetProjectHostingExtensions.AddDotnetProject method adds a C# project or file-based app to the application model using a path to the file-based app .cs file, project file (.csproj), or project directory. If the path is not an absolute path then it will be computed relative to the AppHost directory.

Add a file-based app to the app model via a file path.
var builder = DistributedApplication.CreateBuilder(args);
builder.AddDotnetProject(
"inventoryservice",
@"..\InventoryService.cs",
o => o.LaunchProfileName = "https");
builder.Build().Run();