# ProjectResourceBuilderExtensions Methods

- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Type: [ProjectResourceBuilderExtensions](/reference/api/csharp/aspire.hosting/projectresourcebuilderextensions.md)
- Kind: `Methods`
- Members: `12`

Provides extension methods for [IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md) to add and configure project resources.

## AddCSharpApp(IDistributedApplicationBuilder, string, string)

> **Experimental:** ASPIRECSHARPAPPS001 - [Learn more](/diagnostics/aspirecsharpapps001/)

- Name: `AddCSharpApp(IDistributedApplicationBuilder, string, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<ProjectResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ProjectResourceBuilderExtensions.cs#L353-L357)

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

```csharp
public static class ProjectResourceBuilderExtensions
{
    public static IResourceBuilder<ProjectResource> AddCSharpApp(
        this IDistributedApplicationBuilder builder,
        string name,
        string path)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md))
  The [IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md).
- `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<ProjectResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## Remarks

This overload of the [ProjectResourceBuilderExtensions.AddCSharpApp(IDistributedApplicationBuilder, string, string)](/reference/api/csharp/aspire.hosting/projectresourcebuilderextensions/methods.md#addcsharpapp-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 app host directory.

Add a file-based app to the app model via a file path.

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

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

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

## ATS metadata

### Ignored by ATS

- Reason: Polyglot app hosts use the internal addCSharpApp dispatcher export.

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

> **Experimental:** ASPIRECSHARPAPPS001 - [Learn more](/diagnostics/aspirecsharpapps001/)

- Name: `AddCSharpApp(IDistributedApplicationBuilder, string, string, Action<ProjectResourceOptions>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<CSharpAppResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ProjectResourceBuilderExtensions.cs#L402-L447)

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

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

## Parameters

- `builder` ([IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md))
  The [IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md).
- `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<CSharpAppResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## Remarks

This overload of the [ProjectResourceBuilderExtensions.AddCSharpApp(IDistributedApplicationBuilder, string, string)](/reference/api/csharp/aspire.hosting/projectresourcebuilderextensions/methods.md#addcsharpapp-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 app host directory.

Add a file-based app to the app model via a file path.

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

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

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

## ATS metadata

### Ignored by ATS

- Reason: Polyglot app hosts use the internal addCSharpApp dispatcher export.

## AddProject(IDistributedApplicationBuilder, string)

- Name: `AddProject(IDistributedApplicationBuilder, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<ProjectResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ProjectResourceBuilderExtensions.cs#L70-L73)

Adds a .NET project to the application model.

```csharp
public static class ProjectResourceBuilderExtensions
{
    public static IResourceBuilder<ProjectResource> AddProject<TProject>(
        this IDistributedApplicationBuilder builder,
        string name)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md))
  The [IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md).
- `name` (`string`)
  The name of the resource. This name will be used for service discovery when referenced in a dependency.

## Returns

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

## Remarks

This overload of the [ProjectResourceBuilderExtensions.AddProject(IDistributedApplicationBuilder, string)](/reference/api/csharp/aspire.hosting/projectresourcebuilderextensions/methods.md#addproject-idistributedapplicationbuilder-string) method takes a `TProject` type parameter. The `TProject` type parameter is constrained to types that implement the [IProjectMetadata](/reference/api/csharp/aspire.hosting/iprojectmetadata.md) interface.

Classes that implement the [IProjectMetadata](/reference/api/csharp/aspire.hosting/iprojectmetadata.md) 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 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](/reference/api/csharp/aspire.hosting/endpointannotation.md).

Example of adding a project to the application model.

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

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

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

This method is not available in polyglot app hosts. Use the overload with projectPath instead.

## ATS metadata

### Ignored by ATS

- Reason: Uses IProjectMetadata generic constraint which is a .NET-specific type.

## AddProject(IDistributedApplicationBuilder, string, string)

- Name: `AddProject(IDistributedApplicationBuilder, string, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<ProjectResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ProjectResourceBuilderExtensions.cs#L104-L108)

Adds a .NET project to the application model.

```csharp
public static class ProjectResourceBuilderExtensions
{
    public static IResourceBuilder<ProjectResource> AddProject(
        this IDistributedApplicationBuilder builder,
        string name,
        string projectPath)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md))
  The [IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md).
- `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

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

## Remarks

This overload of the [ProjectResourceBuilderExtensions.AddProject(IDistributedApplicationBuilder, string)](/reference/api/csharp/aspire.hosting/projectresourcebuilderextensions/methods.md#addproject-idistributedapplicationbuilder-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.

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

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

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

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

## ATS metadata

### Ignored by ATS

- Reason: Polyglot app hosts use the internal addProject dispatcher export.

## AddProject(IDistributedApplicationBuilder, string, string?)

- Name: `AddProject(IDistributedApplicationBuilder, string, string?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<ProjectResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ProjectResourceBuilderExtensions.cs#L173-L180)

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.

```csharp
public static class ProjectResourceBuilderExtensions
{
    public static IResourceBuilder<ProjectResource> AddProject<TProject>(
        this IDistributedApplicationBuilder builder,
        string name,
        string? launchProfileName)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md))
  The [IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md).
- `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

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

## Remarks

This overload of the [ProjectResourceBuilderExtensions.AddProject(IDistributedApplicationBuilder, string)](/reference/api/csharp/aspire.hosting/projectresourcebuilderextensions/methods.md#addproject-idistributedapplicationbuilder-string) method takes a `TProject` type parameter. The `TProject` type parameter is constrained to types that implement the [IProjectMetadata](/reference/api/csharp/aspire.hosting/iprojectmetadata.md) interface.

Classes that implement the [IProjectMetadata](/reference/api/csharp/aspire.hosting/iprojectmetadata.md) 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 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.

Example of adding a project to the application model.

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

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

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

This method is not available in polyglot app hosts. Use the overload with projectPath instead.

## ATS metadata

### Ignored by ATS

- Reason: Uses IProjectMetadata generic constraint which is a .NET-specific type.

## AddProject(IDistributedApplicationBuilder, string, string, string?)

- Name: `AddProject(IDistributedApplicationBuilder, string, string, string?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<ProjectResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ProjectResourceBuilderExtensions.cs#L212-L220)

Adds a .NET project to the application model.

```csharp
public static class ProjectResourceBuilderExtensions
{
    public static IResourceBuilder<ProjectResource> AddProject(
        this IDistributedApplicationBuilder builder,
        string name,
        string projectPath,
        string? launchProfileName)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md))
  The [IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md).
- `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

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

## Remarks

This overload of the [ProjectResourceBuilderExtensions.AddProject(IDistributedApplicationBuilder, string)](/reference/api/csharp/aspire.hosting/projectresourcebuilderextensions/methods.md#addproject-idistributedapplicationbuilder-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.

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

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

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

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

## ATS metadata

### Ignored by ATS

- Reason: Polyglot app hosts use the internal addProject dispatcher export.

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

- Name: `AddProject(IDistributedApplicationBuilder, string, Action<ProjectResourceOptions>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<ProjectResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ProjectResourceBuilderExtensions.cs#L263-L276)

Adds a .NET project to the application model.

```csharp
public static class ProjectResourceBuilderExtensions
{
    public static IResourceBuilder<ProjectResource> AddProject<TProject>(
        this IDistributedApplicationBuilder builder,
        string name,
        Action<ProjectResourceOptions> configure)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md))
  The [IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md).
- `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

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

## Remarks

This overload of the [ProjectResourceBuilderExtensions.AddProject(IDistributedApplicationBuilder, string)](/reference/api/csharp/aspire.hosting/projectresourcebuilderextensions/methods.md#addproject-idistributedapplicationbuilder-string) method takes a `TProject` type parameter. The `TProject` type parameter is constrained to types that implement the [IProjectMetadata](/reference/api/csharp/aspire.hosting/iprojectmetadata.md) interface.

Classes that implement the [IProjectMetadata](/reference/api/csharp/aspire.hosting/iprojectmetadata.md) 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 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.

Example of adding a project to the application model.

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

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

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

This method is not available in polyglot app hosts. Use the overload with projectPath instead.

## ATS metadata

### Ignored by ATS

- Reason: Uses IProjectMetadata generic constraint which is a .NET-specific type.

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

- Name: `AddProject(IDistributedApplicationBuilder, string, string, Action<ProjectResourceOptions>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<ProjectResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ProjectResourceBuilderExtensions.cs#L307-L322)

Adds a .NET project to the application model.

```csharp
public static class ProjectResourceBuilderExtensions
{
    public static IResourceBuilder<ProjectResource> AddProject(
        this IDistributedApplicationBuilder builder,
        string name,
        string projectPath,
        Action<ProjectResourceOptions> configure)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md))
  The [IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md).
- `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 or directory.
- `configure` (`Action<ProjectResourceOptions>`)
  A callback to configure the project resource options.

## Returns

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

## Remarks

This overload of the [ProjectResourceBuilderExtensions.AddProject(IDistributedApplicationBuilder, string)](/reference/api/csharp/aspire.hosting/projectresourcebuilderextensions/methods.md#addproject-idistributedapplicationbuilder-string) method adds a project to the application model using a path to the project file or directory. 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.

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

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

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

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

## ATS metadata

### Ignored by ATS

- Reason: Polyglot app hosts use the internal addProject dispatcher export.

## DisableForwardedHeaders(IResourceBuilder<ProjectResource>)

- Name: `DisableForwardedHeaders(IResourceBuilder<ProjectResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<ProjectResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ProjectResourceBuilderExtensions.cs#L831-L834)

Configures the project to disable forwarded headers when being published.

```csharp
public static class ProjectResourceBuilderExtensions
{
    public static IResourceBuilder<ProjectResource> DisableForwardedHeaders(
        this IResourceBuilder<ProjectResource> builder)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<ProjectResource>`)
  The project resource builder.

## Returns

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

## Remarks

By default Aspire assumes that .NET applications which expose endpoints should be configured to use forwarded headers. This is because most typical cloud native deployment scenarios involve a reverse proxy which translates an external endpoint hostname to an internal address.

To enable forwarded headers the `ASPNETCORE_FORWARDEDHEADERS_ENABLED` variable is injected into the project and set to true. If the [ProjectResourceBuilderExtensions.DisableForwardedHeaders(IResourceBuilder<ProjectResource>)](/reference/api/csharp/aspire.hosting/projectresourcebuilderextensions/methods.md#disableforwardedheaders-iresourcebuilder-projectresource) extension is used this environment variable will not be set.

Disable forwarded headers for a project.

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

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

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## PublishAsDockerFile(IResourceBuilder<T>, Action<IResourceBuilder<ContainerResource>>)

- Name: `PublishAsDockerFile(IResourceBuilder<T>, Action<IResourceBuilder<ContainerResource>>)`
- Modifiers: `extension`
- Returns: [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ProjectResourceBuilderExtensions.cs#L875-L922)

Adds support for containerizing this [ProjectResource](/reference/api/csharp/aspire.hosting/projectresource.md) during deployment. The resulting container image is built, and when the optional `configure` action is provided, it is used to configure the container resource.

```csharp
public static class ProjectResourceBuilderExtensions
{
    public static IResourceBuilder<T> PublishAsDockerFile<T>(
        this IResourceBuilder<T> builder,
        Action<IResourceBuilder<ContainerResource>>? configure = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md))
  Resource builder
- `configure` (`Action<IResourceBuilder<ContainerResource>>`) `optional`
  Optional action to configure the container resource

## Returns

[IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## Remarks

When the executable resource is converted to a container resource, the arguments to the executable are not used. This is because arguments to the project often contain physical paths that are not valid in the container. The container can be set up with the correct arguments using the `configure` action.

## ATS metadata

### ATS export

- Capability ID: `Aspire.Hosting/publishProjectAsDockerFileWithConfigure`
- Generated method name override: `publishAsDockerFile`
- Synchronous exports run on a background thread.

## WithEndpointsInEnvironment(IResourceBuilder<ProjectResource>, Func<EndpointAnnotation, bool>)

- Name: `WithEndpointsInEnvironment(IResourceBuilder<ProjectResource>, Func<EndpointAnnotation, bool>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<ProjectResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ProjectResourceBuilderExtensions.cs#L849-L854)

Set a filter that determines if environment variables are injected for a given endpoint. By default, all endpoints are included (if this method is not called).

```csharp
public static class ProjectResourceBuilderExtensions
{
    public static IResourceBuilder<ProjectResource> WithEndpointsInEnvironment(
        this IResourceBuilder<ProjectResource> builder,
        Func<EndpointAnnotation, bool> filter)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<ProjectResource>`)
  The project resource builder.
- `filter` (`Func<EndpointAnnotation, bool>`)
  The filter callback that returns true if and only if the endpoint should be included.

## Returns

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

## Remarks

This method is not available in polyglot app hosts.

## ATS metadata

### Ignored by ATS

- Reason: Uses Func<EndpointAnnotation, bool> which is not ATS-compatible.

## WithReplicas(IResourceBuilder<ProjectResource>, int)

- Name: `WithReplicas(IResourceBuilder<ProjectResource>, int)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<ProjectResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ProjectResourceBuilderExtensions.cs#L796-L799)

Configures how many replicas of the project should be created for the project.

```csharp
public static class ProjectResourceBuilderExtensions
{
    public static IResourceBuilder<ProjectResource> WithReplicas(
        this IResourceBuilder<ProjectResource> builder,
        int replicas)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<ProjectResource>`)
  The project resource builder.
- `replicas` (`int`)
  The number of replicas.

## Returns

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

## Remarks

When this method is applied to a project resource it will configure the app host to start multiple instances of the application based on the specified number of replicas. By default the app host automatically starts a reverse proxy for each process. When [ProjectResourceBuilderExtensions.WithReplicas(IResourceBuilder<ProjectResource>, int)](/reference/api/csharp/aspire.hosting/projectresourcebuilderextensions/methods.md#withreplicas-iresourcebuilder-projectresource-int) is used the reverse proxy will load balance traffic between the replicas.

This capability can be useful when debugging scale out scenarios to ensure state is appropriately managed within a cluster of instances.

Start multiple instances of the same service.

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

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

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.
