# ExecutionConfigurationBuilder Methods

- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Type: [ExecutionConfigurationBuilder](/reference/api/csharp/aspire.hosting/executionconfigurationbuilder.md)
- Kind: `Methods`
- Members: `3`

Provides a builder for constructing an [IExecutionConfigurationResult](/reference/api/csharp/aspire.hosting/iexecutionconfigurationresult.md) for a specific resource in the distributed application model. This resolves command line arguments and environment variables and potentially additional metadata through registered gatherers.

## AddExecutionConfigurationGatherer(IExecutionConfigurationGatherer)

- Name: `AddExecutionConfigurationGatherer(IExecutionConfigurationGatherer)`
- Returns: [IExecutionConfigurationBuilder](/reference/api/csharp/aspire.hosting/iexecutionconfigurationbuilder.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ExecutionConfigurationBuilder.cs#L87-L89)

Adds a configuration gatherer to the builder.

```csharp
public sealed class ExecutionConfigurationBuilder
{
    public IExecutionConfigurationBuilder AddExecutionConfigurationGatherer(
        IExecutionConfigurationGatherer gatherer)
    {
        // ...
    }
}
```

## Parameters

- `gatherer` ([IExecutionConfigurationGatherer](/reference/api/csharp/aspire.hosting/iexecutionconfigurationgatherer.md))
  The configuration gatherer to add.

## Returns

[IExecutionConfigurationBuilder](/reference/api/csharp/aspire.hosting/iexecutionconfigurationbuilder.md) -- The current instance of the builder.

## BuildAsync(DistributedApplicationExecutionContext, ILogger?, CancellationToken)

- Name: `BuildAsync(DistributedApplicationExecutionContext, ILogger?, CancellationToken)`
- Returns: [Task<IExecutionConfigurationResult>](/reference/api/csharp/aspire.hosting/iexecutionconfigurationresult.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ExecutionConfigurationBuilder.cs#L95-L114)

Builds the processed resource configuration (resolved arguments and environment variables).

```csharp
public sealed class ExecutionConfigurationBuilder
{
    public Task<IExecutionConfigurationResult> BuildAsync(
        DistributedApplicationExecutionContext executionContext,
        ILogger? resourceLogger = null,
        CancellationToken cancellationToken = default(CancellationToken))
    {
        // ...
    }
}
```

## Parameters

- `executionContext` ([DistributedApplicationExecutionContext](/reference/api/csharp/aspire.hosting/distributedapplicationexecutioncontext.md))
  The distributed application execution context.
- `resourceLogger` (`ILogger?`) `optional`
  A logger instance for the resource. If none is provided, a default logger will be used.
- `cancellationToken` (`CancellationToken`) `optional`
  A cancellation token.

## Returns

[Task<IExecutionConfigurationResult>](/reference/api/csharp/aspire.hosting/iexecutionconfigurationresult.md) -- The resource configuration result. Any exceptions that occurred while processing are available via the [IExecutionConfigurationResult.Exception](/reference/api/csharp/aspire.hosting/iexecutionconfigurationresult/properties.md#exception) property.

## Create(IResource)

- Name: `Create(IResource)`
- Modifiers: `static`
- Returns: [IExecutionConfigurationBuilder](/reference/api/csharp/aspire.hosting/iexecutionconfigurationbuilder.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ExecutionConfigurationBuilder.cs#L81)

Creates a new instance of [IExecutionConfigurationBuilder](/reference/api/csharp/aspire.hosting/iexecutionconfigurationbuilder.md).

```csharp
public sealed class ExecutionConfigurationBuilder
{
    public static IExecutionConfigurationBuilder Create(
        IResource resource)
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResource](/reference/api/csharp/aspire.hosting/iresource.md))
  The resource to build the configuration for.

## Returns

[IExecutionConfigurationBuilder](/reference/api/csharp/aspire.hosting/iexecutionconfigurationbuilder.md) -- A new [IExecutionConfigurationBuilder](/reference/api/csharp/aspire.hosting/iexecutionconfigurationbuilder.md).

## Remarks

This method is useful for building resource execution configurations (command line arguments and environment variables) in a fluent manner. Individual configuration sources can be added to the builder before finalizing the configuration to allow only supported configuration sources to be applied in a given execution context (run vs. publish, etc).

In particular, this is used to allow certificate-related features to contribute to the final config, but only in execution contexts where they're supported.

```csharp
var resolvedConfiguration = await ExecutionConfigurationBuilder
    .Create(myResource)
    .WithArgumentsConfig()
    .WithEnvironmentVariablesConfig()
    .BuildAsync(executionContext)
    .ConfigureAwait(false);

foreach (var argument in resolvedConfiguration.Arguments)
{
    Console.WriteLine($"Argument: {argument.Value}");
}
```
