# DotnetProjectHostingExtensions Methods

- Package: [Aspire.Hosting.Dotnet](/reference/api/csharp/aspire.hosting.dotnet.md)
- Type: [DotnetProjectHostingExtensions](/reference/api/csharp/aspire.hosting.dotnet/dotnetprojecthostingextensions.md)
- Kind: `Methods`
- Members: `2`

Provides extension methods for adding C# projects and file-based C# apps (by path) to an `Hosting.IDistributedApplicationBuilder`.

<a id="adddotnetproject"></a>
<a id="adddotnetproject-idistributedapplicationbuilder-string-string"></a>

## AddDotnetProject(IDistributedApplicationBuilder, string, string)

> **Experimental:** ASPIREDOTNETPROJECT001 - [Learn more](/diagnostics/aspiredotnetproject001/)

- Name: `AddDotnetProject(IDistributedApplicationBuilder, string, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<DotnetProjectResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/b5f143315ffb6968ea939a9978797a5b20e4c688/src/Aspire.Hosting.Dotnet/DotnetProjectHostingExtensions.cs#L49-L53)

Adds a C# project or file-based app to the application model.

```csharp
public static class DotnetProjectHostingExtensions
{
    public static IResourceBuilder<DotnetProjectResource> AddDotnetProject(
        this IDistributedApplicationBuilder builder,
        string name,
        string path)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
  The `Hosting.IDistributedApplicationBuilder`.
- `name` (`string`)
  The name of the resource. This name will be used for service discovery when referenced in a dependency.
- `path` (`string`)
  The path to the file-based app file, project file, or project directory.

## Returns

`IResourceBuilder<DotnetProjectResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## Remarks

This overload of the [DotnetProjectHostingExtensions.AddDotnetProject(IDistributedApplicationBuilder, string, string)](/reference/api/csharp/aspire.hosting.dotnet/dotnetprojecthostingextensions/methods.md#adddotnetproject-idistributedapplicationbuilder-string-string) 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.

```csharp
var builder = DistributedApplication.CreateBuilder(args);

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

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

## ATS metadata

### Ignored by ATS

- Reason: Polyglot AppHosts use the internal addDotnetProject dispatcher export.

<a id="adddotnetproject-idistributedapplicationbuilder-string-string-action-projectresourceoptions"></a>

## AddDotnetProject(IDistributedApplicationBuilder, string, string, Action<ProjectResourceOptions>)

> **Experimental:** ASPIREDOTNETPROJECT001 - [Learn more](/diagnostics/aspiredotnetproject001/)

- Name: `AddDotnetProject(IDistributedApplicationBuilder, string, string, Action<ProjectResourceOptions>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<DotnetProjectResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/b5f143315ffb6968ea939a9978797a5b20e4c688/src/Aspire.Hosting.Dotnet/DotnetProjectHostingExtensions.cs#L101-L220)

Adds a C# project or file-based app to the application model.

```csharp
public static class DotnetProjectHostingExtensions
{
    public static IResourceBuilder<DotnetProjectResource> AddDotnetProject(
        this IDistributedApplicationBuilder builder,
        string name,
        string path,
        Action<ProjectResourceOptions> configure)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
  The `Hosting.IDistributedApplicationBuilder`.
- `name` (`string`)
  The name of the resource. This name will be used for service discovery when referenced in a dependency.
- `path` (`string`)
  The path to the file-based app file, project file, or project directory.
- `configure` (`Action<ProjectResourceOptions>`)
  An optional action to configure the C# app resource options.

## Returns

`IResourceBuilder<DotnetProjectResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## Remarks

This overload of the [DotnetProjectHostingExtensions.AddDotnetProject(IDistributedApplicationBuilder, string, string)](/reference/api/csharp/aspire.hosting.dotnet/dotnetprojecthostingextensions/methods.md#adddotnetproject-idistributedapplicationbuilder-string-string) 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.

```csharp
var builder = DistributedApplication.CreateBuilder(args);

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

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

## ATS metadata

### Ignored by ATS

- Reason: Polyglot AppHosts use the internal addDotnetProject dispatcher export.
