# ResourceExtensions Methods

- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Type: [ResourceExtensions](/reference/api/csharp/aspire.hosting/resourceextensions.md)
- Kind: `Methods`
- Members: `30`

Provides extension methods for the [IResource](/reference/api/csharp/aspire.hosting/iresource.md) interface.

## GetArgumentValuesAsync(IResourceWithArgs, DistributedApplicationOperation)

> **Obsolete:** Use ExecutionConfigurationBuilder instead.

- Name: `GetArgumentValuesAsync(IResourceWithArgs, DistributedApplicationOperation)`
- Modifiers: `extension`
- Returns: `ValueTask<string[]>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs#L246-L251)

Get the arguments from the given resource.

```csharp
public static class ResourceExtensions
{
    public static ValueTask<string[]> GetArgumentValuesAsync(
        this IResourceWithArgs resource,
        DistributedApplicationOperation applicationOperation = DistributedApplicationOperation.Run)
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResourceWithArgs](/reference/api/csharp/aspire.hosting/iresourcewithargs.md))
  The resource to get the arguments from.
- `applicationOperation` ([DistributedApplicationOperation](/reference/api/csharp/aspire.hosting/distributedapplicationoperation.md)) `optional`
  The context in which the AppHost is being executed.

## Returns

`ValueTask<string[]>` -- The arguments retrieved from the resource.

## Remarks

This method is useful when you want to make sure the arguments are added properly to resources, mostly in test situations. This method has asynchronous behavior when `applicationOperation` is [DistributedApplicationOperation.Run](/reference/api/csharp/aspire.hosting/distributedapplicationoperation/fields.md) and arguments were provided from [IValueProvider](/reference/api/csharp/aspire.hosting/ivalueprovider.md) otherwise it will be synchronous. Using [ResourceExtensions.GetArgumentValuesAsync(IResourceWithArgs, DistributedApplicationOperation)](/reference/api/csharp/aspire.hosting/resourceextensions/methods.md#getargumentvaluesasync-iresourcewithargs-distributedapplicationoperation) inside a unit test to validate argument values.

```csharp
var builder = DistributedApplication.CreateBuilder();
var container = builder.AddContainer("elasticsearch", "library/elasticsearch", "8.14.0")
 .WithArgs("--discovery.type", "single-node")
 .WithArgs("--xpack.security.enabled", "true");

var args = await container.Resource.GetArgumentsAsync();

Assert.Collection(args,
    arg =>
        {
            Assert.Equal("--discovery.type", arg);
        },
        arg =>
        {
            Assert.Equal("--xpack.security.enabled", arg);
        });
```

## GetComputeEnvironment(IResource)

- Name: `GetComputeEnvironment(IResource)`
- Modifiers: `extension` `nullable`
- Returns: [IComputeEnvironmentResource?](/reference/api/csharp/aspire.hosting/icomputeenvironmentresource.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs#L984-L988)

Gets the compute environment that the resource is explicitly bound to, if any.

```csharp
public static class ResourceExtensions
{
    public static IComputeEnvironmentResource? GetComputeEnvironment(
        this IResource resource)
    {
        // ...
    }
}
```

## Parameters

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

## Returns

[IComputeEnvironmentResource?](/reference/api/csharp/aspire.hosting/icomputeenvironmentresource.md) -- The compute environment the resource is bound to, or `null` if the resource is not bound to any specific compute environment.

## ATS metadata

### Ignored by ATS

- Reason: Compute-environment inspection helper -- not part of the ATS surface.

## GetDeploymentTargetAnnotation(IResource, IComputeEnvironmentResource?)

- Name: `GetDeploymentTargetAnnotation(IResource, IComputeEnvironmentResource?)`
- Modifiers: `extension` `nullable`
- Returns: [DeploymentTargetAnnotation?](/reference/api/csharp/aspire.hosting/deploymenttargetannotation.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs#L998-L1038)

Gets the deployment target for the specified resource, if any. Throws an exception if there are multiple compute environments and a compute environment is not explicitly specified.

```csharp
public static class ResourceExtensions
{
    public static DeploymentTargetAnnotation? GetDeploymentTargetAnnotation(
        this IResource resource,
        IComputeEnvironmentResource? targetComputeEnvironment = null)
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResource](/reference/api/csharp/aspire.hosting/iresource.md))
- `targetComputeEnvironment` ([IComputeEnvironmentResource?](/reference/api/csharp/aspire.hosting/icomputeenvironmentresource.md)) `optional`

## ATS metadata

### Ignored by ATS

- Reason: Deployment target inspection helper -- not part of the ATS surface.

## GetEndpoint(IResourceWithEndpoints, string)

- Name: `GetEndpoint(IResourceWithEndpoints, string)`
- Modifiers: `extension`
- Returns: [EndpointReference](/reference/api/csharp/aspire.hosting/endpointreference.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs#L737-L746)

Gets an endpoint reference for the specified endpoint name.

```csharp
public static class ResourceExtensions
{
    public static EndpointReference GetEndpoint(
        this IResourceWithEndpoints resource,
        string endpointName)
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResourceWithEndpoints](/reference/api/csharp/aspire.hosting/iresourcewithendpoints.md))
  The [IResourceWithEndpoints](/reference/api/csharp/aspire.hosting/iresourcewithendpoints.md) which contains [EndpointAnnotation](/reference/api/csharp/aspire.hosting/endpointannotation.md) annotations.
- `endpointName` (`string`)
  The name of the endpoint.

## Returns

[EndpointReference](/reference/api/csharp/aspire.hosting/endpointreference.md) -- An [EndpointReference](/reference/api/csharp/aspire.hosting/endpointreference.md) object providing resolvable reference for the specified endpoint.

## ATS metadata

### Ignored by ATS

- Reason: Resource handle endpoint lookup is not part of the ATS surface; use builder-based endpoint exports instead.

## GetEndpoint(IResourceWithEndpoints, string, NetworkIdentifier)

- Name: `GetEndpoint(IResourceWithEndpoints, string, NetworkIdentifier)`
- Modifiers: `extension`
- Returns: [EndpointReference](/reference/api/csharp/aspire.hosting/endpointreference.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs#L761-L770)

Gets an endpoint reference for the specified endpoint name.

```csharp
public static class ResourceExtensions
{
    public static EndpointReference GetEndpoint(
        this IResourceWithEndpoints resource,
        string endpointName,
        NetworkIdentifier contextNetworkID)
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResourceWithEndpoints](/reference/api/csharp/aspire.hosting/iresourcewithendpoints.md))
  The [IResourceWithEndpoints](/reference/api/csharp/aspire.hosting/iresourcewithendpoints.md) which contains [EndpointAnnotation](/reference/api/csharp/aspire.hosting/endpointannotation.md) annotations.
- `endpointName` (`string`)
  The name of the endpoint.
- `contextNetworkID` ([NetworkIdentifier](/reference/api/csharp/aspire.hosting/networkidentifier.md))
  The network ID of the network that provides the context for the returned [EndpointReference](/reference/api/csharp/aspire.hosting/endpointreference.md)

## Returns

[EndpointReference](/reference/api/csharp/aspire.hosting/endpointreference.md) -- An [EndpointReference](/reference/api/csharp/aspire.hosting/endpointreference.md) object providing resolvable reference for the specified endpoint.

## ATS metadata

### Ignored by ATS

- Reason: Network-specific endpoint lookup is not part of the ATS surface.

## GetEndpoints(IResourceWithEndpoints)

- Name: `GetEndpoints(IResourceWithEndpoints)`
- Modifiers: `extension`
- Returns: [IEnumerable<EndpointReference>](/reference/api/csharp/aspire.hosting/endpointreference.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs#L703-L708)

Gets references to all endpoints for the specified resource.

```csharp
public static class ResourceExtensions
{
    public static IEnumerable<EndpointReference> GetEndpoints(
        this IResourceWithEndpoints resource)
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResourceWithEndpoints](/reference/api/csharp/aspire.hosting/iresourcewithendpoints.md))
  The [IResourceWithEndpoints](/reference/api/csharp/aspire.hosting/iresourcewithendpoints.md) which contains [EndpointAnnotation](/reference/api/csharp/aspire.hosting/endpointannotation.md) annotations.

## Returns

[IEnumerable<EndpointReference>](/reference/api/csharp/aspire.hosting/endpointreference.md) -- An enumeration of [EndpointReference](/reference/api/csharp/aspire.hosting/endpointreference.md) based on the [EndpointAnnotation](/reference/api/csharp/aspire.hosting/endpointannotation.md) annotations from the resources' [IResource.Annotations](/reference/api/csharp/aspire.hosting/iresource/properties.md#annotations) collection.

## ATS metadata

### Ignored by ATS

- Reason: Resource handle endpoint enumeration is not part of the ATS surface; use builder-based endpoint exports instead.

## GetEndpoints(IResourceWithEndpoints, NetworkIdentifier)

- Name: `GetEndpoints(IResourceWithEndpoints, NetworkIdentifier)`
- Modifiers: `extension`
- Returns: [IEnumerable<EndpointReference>](/reference/api/csharp/aspire.hosting/endpointreference.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs#L720-L725)

Gets references to all endpoints for the specified resource.

```csharp
public static class ResourceExtensions
{
    public static IEnumerable<EndpointReference> GetEndpoints(
        this IResourceWithEndpoints resource,
        NetworkIdentifier contextNetworkID)
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResourceWithEndpoints](/reference/api/csharp/aspire.hosting/iresourcewithendpoints.md))
  The [IResourceWithEndpoints](/reference/api/csharp/aspire.hosting/iresourcewithendpoints.md) which contains [EndpointAnnotation](/reference/api/csharp/aspire.hosting/endpointannotation.md) annotations.
- `contextNetworkID` ([NetworkIdentifier](/reference/api/csharp/aspire.hosting/networkidentifier.md))
  The ID of the network that serves as the context context for the endpoint references.

## Returns

[IEnumerable<EndpointReference>](/reference/api/csharp/aspire.hosting/endpointreference.md) -- An enumeration of [EndpointReference](/reference/api/csharp/aspire.hosting/endpointreference.md) based on the [EndpointAnnotation](/reference/api/csharp/aspire.hosting/endpointannotation.md) annotations from the resources' [IResource.Annotations](/reference/api/csharp/aspire.hosting/iresource/properties.md#annotations) collection.

## ATS metadata

### Ignored by ATS

- Reason: Network-specific endpoint enumeration is not part of the ATS surface.

## GetEnvironmentVariableValuesAsync(IResourceWithEnvironment, DistributedApplicationOperation)

> **Obsolete:** Use ExecutionConfigurationBuilder instead.

- Name: `GetEnvironmentVariableValuesAsync(IResourceWithEnvironment, DistributedApplicationOperation)`
- Modifiers: `extension`
- Returns: `ValueTask<Dictionary<string, string>>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs#L202-L207)

Get the environment variables from the given resource.

```csharp
public static class ResourceExtensions
{
    public static ValueTask<Dictionary<string, string>> GetEnvironmentVariableValuesAsync(
        this IResourceWithEnvironment resource,
        DistributedApplicationOperation applicationOperation = DistributedApplicationOperation.Run)
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResourceWithEnvironment](/reference/api/csharp/aspire.hosting/iresourcewithenvironment.md))
  The resource to get the environment variables from.
- `applicationOperation` ([DistributedApplicationOperation](/reference/api/csharp/aspire.hosting/distributedapplicationoperation.md)) `optional`
  The context in which the AppHost is being executed.

## Returns

`ValueTask<Dictionary<string, string>>` -- The environment variables retrieved from the resource.

## Remarks

This method is useful when you want to make sure the environment variables are added properly to resources, mostly in test situations. This method has asynchronous behavior when `applicationOperation` is [DistributedApplicationOperation.Run](/reference/api/csharp/aspire.hosting/distributedapplicationoperation/fields.md) and environment variables were provided from [IValueProvider](/reference/api/csharp/aspire.hosting/ivalueprovider.md) otherwise it will be synchronous. Using [ResourceExtensions.GetEnvironmentVariableValuesAsync(IResourceWithEnvironment, DistributedApplicationOperation)](/reference/api/csharp/aspire.hosting/resourceextensions/methods.md#getenvironmentvariablevaluesasync-iresourcewithenvironment-distributedapplicationoperation) inside a unit test to validate environment variable values.

```csharp
var builder = DistributedApplication.CreateBuilder();
var container = builder.AddContainer("elasticsearch", "library/elasticsearch", "8.14.0")
 .WithEnvironment("discovery.type", "single-node")
 .WithEnvironment("xpack.security.enabled", "true");

var env = await container.Resource.GetEnvironmentVariableValuesAsync();

Assert.Collection(env,
    env =>
        {
            Assert.Equal("discovery.type", env.Key);
            Assert.Equal("single-node", env.Value);
        },
        env =>
        {
            Assert.Equal("xpack.security.enabled", env.Key);
            Assert.Equal("true", env.Value);
        });
```

## GetReplicaCount(IResource)

- Name: `GetReplicaCount(IResource)`
- Modifiers: `extension`
- Returns: `int`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs#L924-L930)

Gets the number of replicas for the specified resource. Defaults to `1` if no [ReplicaAnnotation](/reference/api/csharp/aspire.hosting/replicaannotation.md) is found.

```csharp
public static class ResourceExtensions
{
    public static int GetReplicaCount(
        this IResource resource)
    {
        // ...
    }
}
```

## Parameters

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

## Returns

`int` -- The number of replicas for the specified resource.

## ATS metadata

### Ignored by ATS

- Reason: Replica inspection helper -- not part of the ATS surface.

## GetResourceDependenciesAsync(IResource, DistributedApplicationExecutionContext, ResourceDependencyDiscoveryMode, CancellationToken)

- Name: `GetResourceDependenciesAsync(IResource, DistributedApplicationExecutionContext, ResourceDependencyDiscoveryMode, CancellationToken)`
- Modifiers: `extension`
- Returns: [Task<IReadOnlySet<IResource>>](/reference/api/csharp/aspire.hosting/iresource.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs#L1329)

Computes the set of resources that the specified `resource` depends on.

```csharp
public static class ResourceExtensions
{
    public static Task<IReadOnlySet<IResource>> GetResourceDependenciesAsync(
        this IResource resource,
        DistributedApplicationExecutionContext executionContext,
        ResourceDependencyDiscoveryMode mode = ResourceDependencyDiscoveryMode.Recursive,
        CancellationToken cancellationToken = default(CancellationToken))
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResource](/reference/api/csharp/aspire.hosting/iresource.md))
  The resource to compute dependencies for.
- `executionContext` ([DistributedApplicationExecutionContext](/reference/api/csharp/aspire.hosting/distributedapplicationexecutioncontext.md))
  The execution context for resolving environment variables and arguments.
- `mode` ([ResourceDependencyDiscoveryMode](/reference/api/csharp/aspire.hosting/resourcedependencydiscoverymode.md)) `optional`
  Specifies dependency discovery mode.
- `cancellationToken` (`CancellationToken`) `optional`
  A cancellation token to observe while computing dependencies.

## Returns

[Task<IReadOnlySet<IResource>>](/reference/api/csharp/aspire.hosting/iresource.md) -- A set of all resources that the specified resource depends on.

## Remarks

Dependencies are computed from multiple sources:

- Parent resources via [IResourceWithParent](/reference/api/csharp/aspire.hosting/iresourcewithparent.md)
- Wait dependencies via [WaitAnnotation](/reference/api/csharp/aspire.hosting/waitannotation.md)
- Connection string redirects via [ConnectionStringRedirectAnnotation](/reference/api/csharp/aspire.hosting/connectionstringredirectannotation.md)
- References to endpoints in environment variables and command-line arguments (via [IValueWithReferences](/reference/api/csharp/aspire.hosting/ivaluewithreferences.md))

When `mode` is [ResourceDependencyDiscoveryMode.DirectOnly](/reference/api/csharp/aspire.hosting/resourcedependencydiscoverymode/fields.md), only the immediate dependencies are returned. When `mode` is [ResourceDependencyDiscoveryMode.Recursive](/reference/api/csharp/aspire.hosting/resourcedependencydiscoverymode/fields.md), all transitive dependencies are included.

This method invokes environment variable and command-line argument callbacks to discover all references. The context resource ( `resource`) is not considered a dependency (even if it is transitively referenced).

## ATS metadata

### Ignored by ATS

- Reason: Dependency discovery helper depends on execution context and is not part of the ATS surface.

## GetResourceDependenciesAsync(IResource, DistributedApplicationExecutionContext, ResourceDependencyDiscoveryOptions, CancellationToken)

- Name: `GetResourceDependenciesAsync(IResource, DistributedApplicationExecutionContext, ResourceDependencyDiscoveryOptions, CancellationToken)`
- Modifiers: `extension`
- Returns: [Task<IReadOnlySet<IResource>>](/reference/api/csharp/aspire.hosting/iresource.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs#L1361)

Computes the set of resources that the specified `resource` depends on.

```csharp
public static class ResourceExtensions
{
    public static Task<IReadOnlySet<IResource>> GetResourceDependenciesAsync(
        this IResource resource,
        DistributedApplicationExecutionContext executionContext,
        ResourceDependencyDiscoveryOptions options,
        CancellationToken cancellationToken = default(CancellationToken))
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResource](/reference/api/csharp/aspire.hosting/iresource.md))
  The resource to compute dependencies for.
- `executionContext` ([DistributedApplicationExecutionContext](/reference/api/csharp/aspire.hosting/distributedapplicationexecutioncontext.md))
  The execution context for resolving environment variables and arguments.
- `options` ([ResourceDependencyDiscoveryOptions](/reference/api/csharp/aspire.hosting/resourcedependencydiscoveryoptions.md))
  Changes details of dependency discovery process. See [ResourceDependencyDiscoveryOptions](/reference/api/csharp/aspire.hosting/resourcedependencydiscoveryoptions.md) enumeration for more information.
- `cancellationToken` (`CancellationToken`) `optional`
  A cancellation token to observe while computing dependencies.

## Returns

[Task<IReadOnlySet<IResource>>](/reference/api/csharp/aspire.hosting/iresource.md) -- A set of all resources that the specified resource depends on.

## Remarks

Dependencies are computed from multiple sources:

- Parent resources via [IResourceWithParent](/reference/api/csharp/aspire.hosting/iresourcewithparent.md)
- Wait dependencies via [WaitAnnotation](/reference/api/csharp/aspire.hosting/waitannotation.md)
- Connection string redirects via [ConnectionStringRedirectAnnotation](/reference/api/csharp/aspire.hosting/connectionstringredirectannotation.md)
- References to endpoints in environment variables and command-line arguments (via [IValueWithReferences](/reference/api/csharp/aspire.hosting/ivaluewithreferences.md))

This method invokes environment variable and command-line argument callbacks to discover all references. The context resource ( `resource`) is not considered a dependency (even if it is transitively referenced).

## ATS metadata

### Ignored by ATS

- Reason: Parameters and return type are not ATS-compatible -- internal dependency discovery helper.

## HasAnnotationIncludingAncestorsOfType(IResource)

- Name: `HasAnnotationIncludingAncestorsOfType(IResource)`
- Modifiers: `extension`
- Returns: `bool`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs#L126-L148)

Gets whether `resource` or its ancestors have an annotation of type `T`

```csharp
public static class ResourceExtensions
{
    public static bool HasAnnotationIncludingAncestorsOfType<T>(
        this IResource resource)
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResource](/reference/api/csharp/aspire.hosting/iresource.md))
  The resource to retrieve annotations from.

## Returns

`bool` -- `true` if an annotation of the specified type was found; otherwise, `false`.

## ATS metadata

### Ignored by ATS

- Reason: Generic annotation inspection helper -- not part of the ATS surface.

## HasAnnotationOfType(IResource)

- Name: `HasAnnotationOfType(IResource)`
- Modifiers: `extension`
- Returns: `bool`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs#L75)

Gets whether `resource` has an annotation of type `T`

```csharp
public static class ResourceExtensions
{
    public static bool HasAnnotationOfType<T>(
        this IResource resource)
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResource](/reference/api/csharp/aspire.hosting/iresource.md))
  The resource to retrieve annotations from.

## Returns

`bool` -- `true` if an annotation of the specified type was found; otherwise, `false`.

## ATS metadata

### Ignored by ATS

- Reason: Generic annotation inspection helper -- not part of the ATS surface.

## IsExcludedFromPublish(IResource)

- Name: `IsExcludedFromPublish(IResource)`
- Modifiers: `extension`
- Returns: `bool`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs#L556)

Gets a value indicating whether the resource is excluded from being published.

```csharp
public static class ResourceExtensions
{
    public static bool IsExcludedFromPublish(
        this IResource resource)
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResource](/reference/api/csharp/aspire.hosting/iresource.md))
  The resource to determine if it should be excluded from being published.

## ATS metadata

### Ignored by ATS

- Reason: Manifest inspection helper -- not part of the ATS surface.

## ProcessArgumentValuesAsync(IResource, DistributedApplicationExecutionContext, Action<object?, string?, Exception?, bool>, ILogger, CancellationToken)

> **Obsolete:** Use ExecutionConfigurationBuilder instead.

- Name: `ProcessArgumentValuesAsync(IResource, DistributedApplicationExecutionContext, Action<object?, string?, Exception?, bool>, ILogger, CancellationToken)`
- Modifiers: `extension`
- Returns: `ValueTask`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs#L346-L349)

Processes argument values for the specified resource in the given execution context.

```csharp
public static class ResourceExtensions
{
    public static ValueTask ProcessArgumentValuesAsync(
        this IResource resource,
        DistributedApplicationExecutionContext executionContext,
        Action<object?, string?, Exception?, bool> processValue,
        ILogger logger,
        CancellationToken cancellationToken = default(CancellationToken))
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResource](/reference/api/csharp/aspire.hosting/iresource.md))
  The resource containing the argument values to process.
- `executionContext` ([DistributedApplicationExecutionContext](/reference/api/csharp/aspire.hosting/distributedapplicationexecutioncontext.md))
  The execution context used during the processing of argument values.
- `processValue` (`Action<object?, string?, Exception?, bool>`)
  A callback invoked for each argument value. This action provides the unprocessed value, processed string representation, an exception if one occurs, and a boolean indicating the success of processing.
- `logger` (`ILogger`)
  The logger used for logging information or errors during the argument processing.
- `cancellationToken` (`CancellationToken`) `optional`
  A token for cancelling the operation, if needed.

## Returns

`ValueTask` -- A task representing the asynchronous operation.

## ProcessEnvironmentVariableValuesAsync(IResource, DistributedApplicationExecutionContext, Action<string, object?, string?, Exception?>, ILogger, CancellationToken)

> **Obsolete:** Use ExecutionConfigurationBuilder instead.

- Name: `ProcessEnvironmentVariableValuesAsync(IResource, DistributedApplicationExecutionContext, Action<string, object?, string?, Exception?>, ILogger, CancellationToken)`
- Modifiers: `extension`
- Returns: `ValueTask`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs#L438-L441)

Processes environment variable values for the specified resource within the given execution context.

```csharp
public static class ResourceExtensions
{
    public static ValueTask ProcessEnvironmentVariableValuesAsync(
        this IResource resource,
        DistributedApplicationExecutionContext executionContext,
        Action<string, object?, string?, Exception?> processValue,
        ILogger logger,
        CancellationToken cancellationToken = default(CancellationToken))
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResource](/reference/api/csharp/aspire.hosting/iresource.md))
  The resource from which the environment variables are retrieved and processed.
- `executionContext` ([DistributedApplicationExecutionContext](/reference/api/csharp/aspire.hosting/distributedapplicationexecutioncontext.md))
  The execution context to be used for processing the environment variables.
- `processValue` (`Action<string, object?, string?, Exception?>`)
  An action delegate invoked for each environment variable, providing the key, the unprocessed value, the processed value (if available), and any exception encountered during processing.
- `logger` (`ILogger`)
  The logger used to log any information or errors during the environment variables processing.
- `cancellationToken` (`CancellationToken`) `optional`
  A cancellation token to observe during the asynchronous operation.

## Returns

`ValueTask` -- A task that represents the asynchronous operation.

## RequiresImageBuild(IResource)

- Name: `RequiresImageBuild(IResource)`
- Modifiers: `extension`
- Returns: `bool`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs#L946-L951)

Determines whether the specified resource requires image building.

```csharp
public static class ResourceExtensions
{
    public static bool RequiresImageBuild(
        this IResource resource)
    {
        // ...
    }
}
```

## Parameters

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

## Returns

`bool` -- True if the resource requires image building; otherwise, false.

## Remarks

Resources require an image build if they provide their own Dockerfile or are a project. Resources that are excluded from publishing are not considered to require image building.

## ATS metadata

### Ignored by ATS

- Reason: Publishing inspection helper -- not part of the ATS surface.

## RequiresImageBuildAndPush(IResource)

- Name: `RequiresImageBuildAndPush(IResource)`
- Modifiers: `extension`
- Returns: `bool`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs#L967)

Determines whether the specified resource requires image building and pushing.

```csharp
public static class ResourceExtensions
{
    public static bool RequiresImageBuildAndPush(
        this IResource resource)
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResource](/reference/api/csharp/aspire.hosting/iresource.md))
  The resource to evaluate for image push requirements.

## Returns

`bool` -- True if the resource requires image building and pushing; otherwise, false.

## Remarks

Resources require an image build and a push to a container registry if they provide their own Dockerfile or are a project. Resources that are excluded from publishing are not considered to require image building and pushing.

## ATS metadata

### Ignored by ATS

- Reason: Publishing inspection helper -- not part of the ATS surface.

## ResolveEndpoints(IResource, IPortAllocator?)

- Name: `ResolveEndpoints(IResource, IPortAllocator?)`
- Modifiers: `extension`
- Returns: [IReadOnlyList<ResolvedEndpoint>](/reference/api/csharp/aspire.hosting/resolvedendpoint.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs#L785-L855)

Resolves endpoint port configuration for the specified resource. Computes target ports and exposed ports based on resource type, endpoint configuration, and whether the endpoint is considered a default HTTP endpoint.

```csharp
public static class ResourceExtensions
{
    public static IReadOnlyList<ResolvedEndpoint> ResolveEndpoints(
        this IResource resource,
        IPortAllocator? portAllocator = null)
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResource](/reference/api/csharp/aspire.hosting/iresource.md))
  The resource containing endpoints to resolve.
- `portAllocator` ([IPortAllocator?](/reference/api/csharp/aspire.hosting/iportallocator.md)) `optional`
  Optional port allocator. If null, uses default allocation starting from port 8000.

## Returns

[IReadOnlyList<ResolvedEndpoint>](/reference/api/csharp/aspire.hosting/resolvedendpoint.md) -- A read-only list of resolved endpoints with computed port values.

## ATS metadata

### Ignored by ATS

- Reason: Endpoint resolution exposes infrastructure-specific types that are not part of the ATS surface.

## TryGetAnnotationsIncludingAncestorsOfType(IResource, IEnumerable<T>)

- Name: `TryGetAnnotationsIncludingAncestorsOfType(IResource, IEnumerable<T>)`
- Modifiers: `extension`
- Returns: `bool`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs#L88-L114)

Attempts to retrieve all annotations of the specified type from the given resource including from parents.

```csharp
public static class ResourceExtensions
{
    public static bool TryGetAnnotationsIncludingAncestorsOfType<T>(
        this IResource resource,
        out IEnumerable<T>? result)
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResource](/reference/api/csharp/aspire.hosting/iresource.md))
  The resource to retrieve annotations from.
- `result` (`IEnumerable<T>`)
  When this method returns, contains the annotations of the specified type, if found; otherwise, `null`.

## Returns

`bool` -- `true` if annotations of the specified type were found; otherwise, `false`.

## ATS metadata

### Ignored by ATS

- Reason: Generic annotation inspection helper -- not part of the ATS surface.

## TryGetAnnotationsOfType(IResource, IEnumerable<T>)

- Name: `TryGetAnnotationsOfType(IResource, IEnumerable<T>)`
- Modifiers: `extension`
- Returns: `bool`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs#L52-L62)

Attempts to retrieve all annotations of the specified type from the given resource.

```csharp
public static class ResourceExtensions
{
    public static bool TryGetAnnotationsOfType<T>(
        this IResource resource,
        out IEnumerable<T>? result)
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResource](/reference/api/csharp/aspire.hosting/iresource.md))
  The resource to retrieve annotations from.
- `result` (`IEnumerable<T>`)
  When this method returns, contains the annotations of the specified type, if found; otherwise, `null`.

## Returns

`bool` -- `true` if annotations of the specified type were found; otherwise, `false`.

## ATS metadata

### Ignored by ATS

- Reason: Generic annotation inspection helper -- not part of the ATS surface.

## TryGetContainerImageName(IResource, string?)

- Name: `TryGetContainerImageName(IResource, string?)`
- Modifiers: `extension`
- Returns: `bool`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs#L869)

Attempts to get the container image name from the given resource.

```csharp
public static class ResourceExtensions
{
    public static bool TryGetContainerImageName(
        this IResource resource,
        out string? imageName)
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResource](/reference/api/csharp/aspire.hosting/iresource.md))
  The resource to get the container image name from.
- `imageName` (`string?`)
  The container image name if found, otherwise null.

## Returns

`bool` -- True if the container image name was found, otherwise false.

## ATS metadata

### Ignored by ATS

- Reason: Container image inspection helper -- not part of the ATS surface.

## TryGetContainerImageName(IResource, bool, string?)

- Name: `TryGetContainerImageName(IResource, bool, string?)`
- Modifiers: `extension`
- Returns: `bool`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs#L884-L912)

Attempts to get the container image name from the given resource.

```csharp
public static class ResourceExtensions
{
    public static bool TryGetContainerImageName(
        this IResource resource,
        bool useBuiltImage,
        out string? imageName)
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResource](/reference/api/csharp/aspire.hosting/iresource.md))
  The resource to get the container image name from.
- `useBuiltImage` (`bool`)
  When true, uses the image name from DockerfileBuildAnnotation if present. When false, uses only ContainerImageAnnotation.
- `imageName` (`string?`)
  The container image name if found, otherwise null.

## Returns

`bool` -- True if the container image name was found, otherwise false.

## ATS metadata

### Ignored by ATS

- Reason: Container image inspection helper -- not part of the ATS surface.

## TryGetContainerMounts(IResource, IEnumerable<ContainerMountAnnotation>)

- Name: `TryGetContainerMounts(IResource, IEnumerable<ContainerMountAnnotation>)`
- Modifiers: `extension`
- Returns: `bool`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs#L668)

Attempts to get the container mounts for the specified resource.

```csharp
public static class ResourceExtensions
{
    public static bool TryGetContainerMounts(
        this IResource resource,
        out IEnumerable<ContainerMountAnnotation>? volumeMounts)
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResource](/reference/api/csharp/aspire.hosting/iresource.md))
  The resource to get the volume mounts for.
- `volumeMounts` ([IEnumerable<ContainerMountAnnotation>](/reference/api/csharp/aspire.hosting/containermountannotation.md))
  When this method returns, contains the volume mounts for the specified resource, if found; otherwise, `null`.

## Returns

`bool` -- `true` if the volume mounts were successfully retrieved; otherwise, `false`.

## ATS metadata

### Ignored by ATS

- Reason: Container mount inspection helper -- not part of the ATS surface.

## TryGetEndpoints(IResource, IEnumerable<EndpointAnnotation>)

- Name: `TryGetEndpoints(IResource, IEnumerable<EndpointAnnotation>)`
- Modifiers: `extension`
- Returns: `bool`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs#L680)

Attempts to retrieve the endpoints for the given resource.

```csharp
public static class ResourceExtensions
{
    public static bool TryGetEndpoints(
        this IResource resource,
        out IEnumerable<EndpointAnnotation>? endpoints)
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResource](/reference/api/csharp/aspire.hosting/iresource.md))
  The resource to retrieve the endpoints for.
- `endpoints` ([IEnumerable<EndpointAnnotation>](/reference/api/csharp/aspire.hosting/endpointannotation.md))
  The endpoints for the given resource, if found.

## Returns

`bool` -- True if the endpoints were found, false otherwise.

## ATS metadata

### Ignored by ATS

- Reason: Endpoint annotation inspection helper -- not part of the ATS surface.

## TryGetEnvironmentVariables(IResource, IEnumerable<EnvironmentCallbackAnnotation>)

- Name: `TryGetEnvironmentVariables(IResource, IEnumerable<EnvironmentCallbackAnnotation>)`
- Modifiers: `extension`
- Returns: `bool`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs#L160)

Attempts to get the environment variables from the given resource.

```csharp
public static class ResourceExtensions
{
    public static bool TryGetEnvironmentVariables(
        this IResource resource,
        out IEnumerable<EnvironmentCallbackAnnotation>? environmentVariables)
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResource](/reference/api/csharp/aspire.hosting/iresource.md))
  The resource to get the environment variables from.
- `environmentVariables` ([IEnumerable<EnvironmentCallbackAnnotation>](/reference/api/csharp/aspire.hosting/environmentcallbackannotation.md))
  The environment variables retrieved from the resource, if any.

## Returns

`bool` -- True if the environment variables were successfully retrieved, false otherwise.

## ATS metadata

### Ignored by ATS

- Reason: Environment callback inspection helper -- not part of the ATS surface.

## TryGetLastAnnotation(IResource, T?)

- Name: `TryGetLastAnnotation(IResource, T?)`
- Modifiers: `extension`
- Returns: `bool`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs#L30-L38)

Attempts to get the last annotation of the specified type from the resource.

```csharp
public static class ResourceExtensions
{
    public static bool TryGetLastAnnotation<T>(
        this IResource resource,
        out T? annotation)
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResource](/reference/api/csharp/aspire.hosting/iresource.md))
  The resource to get the annotation from.
- `annotation` (`T?`)
  When this method returns, contains the last annotation of the specified type from the resource, if found; otherwise, the default value for `T`.

## Returns

`bool` -- `true` if the last annotation of the specified type was found in the resource; otherwise, `false`.

## ATS metadata

### Ignored by ATS

- Reason: Generic annotation inspection helper -- not part of the ATS surface.

## TryGetUrls(IResource, IEnumerable<ResourceUrlAnnotation>)

- Name: `TryGetUrls(IResource, IEnumerable<ResourceUrlAnnotation>)`
- Modifiers: `extension`
- Returns: `bool`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs#L692)

Attempts to retrieve the URLs for the given resource.

```csharp
public static class ResourceExtensions
{
    public static bool TryGetUrls(
        this IResource resource,
        out IEnumerable<ResourceUrlAnnotation>? urls)
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResource](/reference/api/csharp/aspire.hosting/iresource.md))
  The resource to retrieve the URLs for.
- `urls` ([IEnumerable<ResourceUrlAnnotation>](/reference/api/csharp/aspire.hosting/resourceurlannotation.md))
  The URLs for the given resource, if found.

## Returns

`bool` -- True if the URLs were found, false otherwise.

## ATS metadata

### Ignored by ATS

- Reason: URL annotation inspection helper -- not part of the ATS surface.

## WithContainerBuildOptions(IResourceBuilder<T>, Action<ContainerBuildOptionsCallbackContext>)

> **Experimental:** ASPIREPIPELINES003 - [Learn more](/diagnostics/aspirepipelines003/)

- Name: `WithContainerBuildOptions(IResourceBuilder<T>, Action<ContainerBuildOptionsCallbackContext>)`
- 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/ApplicationModel/ResourceExtensions.cs)

Configures container build options for a compute resource using a callback.

```csharp
public static class ResourceExtensions
{
    public static IResourceBuilder<T> WithContainerBuildOptions<T>(
        this IResourceBuilder<T> builder,
        Action<ContainerBuildOptionsCallbackContext> callback)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md))
  The resource builder.
- `callback` (`Action<ContainerBuildOptionsCallbackContext>`)
  A callback to configure container build options.

## Returns

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

## Remarks

This method is not available in polyglot app hosts.

## ATS metadata

### Ignored by ATS

- Reason: ContainerBuildOptionsCallbackContext exposes IResource and IServiceProvider -- .NET runtime types not usable from polyglot hosts.

## WithContainerBuildOptions(IResourceBuilder<T>, Func<ContainerBuildOptionsCallbackContext, Task>)

> **Experimental:** ASPIREPIPELINES003 - [Learn more](/diagnostics/aspirepipelines003/)

- Name: `WithContainerBuildOptions(IResourceBuilder<T>, Func<ContainerBuildOptionsCallbackContext, Task>)`
- 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/ApplicationModel/ResourceExtensions.cs)

Configures container build options for a compute resource using an async callback.

```csharp
public static class ResourceExtensions
{
    public static IResourceBuilder<T> WithContainerBuildOptions<T>(
        this IResourceBuilder<T> builder,
        Func<ContainerBuildOptionsCallbackContext, Task> callback)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md))
  The resource builder.
- `callback` (`Func<ContainerBuildOptionsCallbackContext, Task>`)
  An async callback to configure container build options.

## Returns

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

## Remarks

This method is not available in polyglot app hosts.

## ATS metadata

### Ignored by ATS

- Reason: ContainerBuildOptionsCallbackContext exposes IResource and IServiceProvider -- .NET runtime types not usable from polyglot hosts.
