# DotnetProgramResourceBuilderExtensions Methods

- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Type: [DotnetProgramResourceBuilderExtensions](/reference/api/csharp/aspire.hosting/dotnetprogramresourcebuilderextensions.md)
- Kind: `Methods`
- Members: `5`

Provides publishing configuration for resources backed by .NET programs.

<a id="disableforwardedheaders"></a>
<a id="disableforwardedheaders-iresourcebuilder-t"></a>

## DisableForwardedHeaders(IResourceBuilder<T>)

- Name: `DisableForwardedHeaders(IResourceBuilder<T>)`
- Modifiers: `extension`
- Returns: [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/f4c27f2d43ddc1cacd0dd083b30d1fea1cee7a62/src/Aspire.Hosting/DotnetProgramResourceBuilderExtensions.cs#L42-L44)

Configures the .NET program to omit automatic forwarded-header configuration when publishing.

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

## Parameters

- `builder` ([IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md))
  The resource builder.

## Returns

[IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) -- The resource builder for chaining.

## ATS metadata

### Ignored by ATS

- Reason: Polyglot integrations export concrete resource overloads so fluent APIs preserve their concrete builder type.

<a id="withdotnetprogrambuildenvironment"></a>
<a id="withdotnetprogrambuildenvironment-iresourcebuilder-t-func-environmentcallbackcontext-task"></a>

## WithDotnetProgramBuildEnvironment(IResourceBuilder<T>, Func<EnvironmentCallbackContext, Task>)

- Name: `WithDotnetProgramBuildEnvironment(IResourceBuilder<T>, Func<EnvironmentCallbackContext, Task>)`
- Modifiers: `extension`
- Returns: [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/f4c27f2d43ddc1cacd0dd083b30d1fea1cee7a62/src/Aspire.Hosting/DotnetProgramResourceBuilderExtensions.cs#L94-L97)

Adds a callback that configures build-only environment variables for .NET SDK container publishing.

```csharp
public static class DotnetProgramResourceBuilderExtensions
{
    public static IResourceBuilder<T> WithDotnetProgramBuildEnvironment<T>(
        this IResourceBuilder<T> builder,
        Func<EnvironmentCallbackContext, Task> callback)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md))
  The resource builder.
- `callback` (`Func<EnvironmentCallbackContext, Task>`)
  The callback that configures the build environment.

## Returns

[IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) -- The resource builder for chaining.

## Exceptions

- `ArgumentNullException` -- Thrown when `builder` or `callback` is `null`.

## Remarks

Values supplied through this callback affect the publishing MSBuild evaluation and may appear in build diagnostics. They are not a secret transport. Callbacks are evaluated in registration order for each publish build.

When publishing a container, Aspire rejects values that control the output artifact's identity, destination, format, or target platform because downstream publishing steps use the corresponding container build options. Configure those values with `WithContainerBuildOptions`.

## ATS metadata

### Ignored by ATS

- Reason: Integration authoring API with a raw delegate callback that is not ATS-compatible.

<a id="withdotnetprogrampublishing"></a>
<a id="withdotnetprogrampublishing-iresourcebuilder-t"></a>

## WithDotnetProgramPublishing(IResourceBuilder<T>)

- Name: `WithDotnetProgramPublishing(IResourceBuilder<T>)`
- Modifiers: `extension`
- Returns: [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/f4c27f2d43ddc1cacd0dd083b30d1fea1cee7a62/src/Aspire.Hosting/DotnetProgramResourceBuilderExtensions.cs#L118-L129)

Configures a .NET program resource to publish a container image through the .NET SDK.

```csharp
public static class DotnetProgramResourceBuilderExtensions
{
    public static IResourceBuilder<T> WithDotnetProgramPublishing<T>(
        this IResourceBuilder<T> builder)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md))
  The resource builder.

## Returns

[IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) -- The resource builder for chaining.

## Exceptions

- `InvalidOperationException` -- The resource does not implement [IComputeResource](/reference/api/csharp/aspire.hosting/icomputeresource.md) or does not carry exactly one stable [IProjectMetadata](/reference/api/csharp/aspire.hosting/iprojectmetadata.md) annotation.

## Remarks

This method is intended for .NET language integrations that model programs without deriving from [ProjectResource](/reference/api/csharp/aspire.hosting/projectresource.md). Ordinary projects created with `AddProject` are configured automatically.

## ATS metadata

### Ignored by ATS

- Reason: Integration authoring API that depends on .NET project metadata and is not part of the ATS surface.

<a id="withendpointsinenvironment"></a>
<a id="withendpointsinenvironment-iresourcebuilder-t-func-endpointannotation-bool"></a>

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

- Name: `WithEndpointsInEnvironment(IResourceBuilder<T>, Func<EndpointAnnotation, bool>)`
- Modifiers: `extension`
- Returns: [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/f4c27f2d43ddc1cacd0dd083b30d1fea1cee7a62/src/Aspire.Hosting/DotnetProgramResourceBuilderExtensions.cs#L60-L64)

Configures which endpoints contribute environment variables for the .NET program.

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

## Parameters

- `builder` ([IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md))
  The resource builder.
- `filter` (`Func<EndpointAnnotation, bool>`)
  The endpoint inclusion filter.

## Returns

[IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) -- The resource builder for chaining.

## ATS metadata

### Ignored by ATS

- Reason: Uses Func<EndpointAnnotation, bool>; polyglot AppHosts use the endpoint-name dispatcher.

<a id="withreplicas"></a>
<a id="withreplicas-iresourcebuilder-t-int"></a>

## WithReplicas(IResourceBuilder<T>, int)

- Name: `WithReplicas(IResourceBuilder<T>, int)`
- Modifiers: `extension`
- Returns: [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/f4c27f2d43ddc1cacd0dd083b30d1fea1cee7a62/src/Aspire.Hosting/DotnetProgramResourceBuilderExtensions.cs#L26-L29)

Configures the .NET program to run the specified number of replicas.

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

## Parameters

- `builder` ([IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md))
  The resource builder.
- `replicas` (`int`)
  The number of replicas.

## Returns

[IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) -- The resource builder for chaining.

## ATS metadata

### Ignored by ATS

- Reason: Polyglot integrations export concrete resource overloads so fluent APIs preserve their concrete builder type.
