# ResourceExtensions

- Kind: `class`
- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Version: `13.3.0`
- Namespace: `Aspire.Hosting.ApplicationModel`
- Target framework: `net8.0`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs)

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

## Definition

```csharp
namespace Aspire.Hosting.ApplicationModel;

public static class ResourceExtensions
{
    // ...
}
```

## Methods

- [GetArgumentValuesAsync(IResourceWithArgs, DistributedApplicationOperation)](/reference/api/csharp/aspire.hosting/resourceextensions/methods.md#getargumentvaluesasync-iresourcewithargs-distributedapplicationoperation) : `ValueTask<string[]>` `extension` `obsolete` -- Get the arguments from the given resource.
- [GetComputeEnvironment(IResource)](/reference/api/csharp/aspire.hosting/resourceextensions/methods.md#getcomputeenvironment-iresource) : [IComputeEnvironmentResource?](/reference/api/csharp/aspire.hosting/icomputeenvironmentresource.md) `extension` `ats ignored` -- Gets the compute environment that the resource is explicitly bound to, if any.
- [GetDeploymentTargetAnnotation(IResource, IComputeEnvironmentResource?)](/reference/api/csharp/aspire.hosting/resourceextensions/methods.md#getdeploymenttargetannotation-iresource-icomputeenvironmentresource) : [DeploymentTargetAnnotation?](/reference/api/csharp/aspire.hosting/deploymenttargetannotation.md) `extension` `ats ignored` -- 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.
- [GetEndpoint(IResourceWithEndpoints, string)](/reference/api/csharp/aspire.hosting/resourceextensions/methods.md#getendpoint-iresourcewithendpoints-string) : [EndpointReference](/reference/api/csharp/aspire.hosting/endpointreference.md) `extension` `ats ignored` -- Gets an endpoint reference for the specified endpoint name.
- [GetEndpoint(IResourceWithEndpoints, string, NetworkIdentifier)](/reference/api/csharp/aspire.hosting/resourceextensions/methods.md#getendpoint-iresourcewithendpoints-string-networkidentifier) : [EndpointReference](/reference/api/csharp/aspire.hosting/endpointreference.md) `extension` `ats ignored` -- Gets an endpoint reference for the specified endpoint name.
- [GetEndpoints(IResourceWithEndpoints)](/reference/api/csharp/aspire.hosting/resourceextensions/methods.md#getendpoints-iresourcewithendpoints) : [IEnumerable<EndpointReference>](/reference/api/csharp/aspire.hosting/endpointreference.md) `extension` `ats ignored` -- Gets references to all endpoints for the specified resource.
- [GetEndpoints(IResourceWithEndpoints, NetworkIdentifier)](/reference/api/csharp/aspire.hosting/resourceextensions/methods.md#getendpoints-iresourcewithendpoints-networkidentifier) : [IEnumerable<EndpointReference>](/reference/api/csharp/aspire.hosting/endpointreference.md) `extension` `ats ignored` -- Gets references to all endpoints for the specified resource.
- [GetEnvironmentVariableValuesAsync(IResourceWithEnvironment, DistributedApplicationOperation)](/reference/api/csharp/aspire.hosting/resourceextensions/methods.md#getenvironmentvariablevaluesasync-iresourcewithenvironment-distributedapplicationoperation) : `ValueTask<Dictionary<string, string>>` `extension` `obsolete` -- Get the environment variables from the given resource.
- [GetReplicaCount(IResource)](/reference/api/csharp/aspire.hosting/resourceextensions/methods.md#getreplicacount-iresource) : `int` `extension` `ats ignored` -- Gets the number of replicas for the specified resource. Defaults to `1` if no [ReplicaAnnotation](/reference/api/csharp/aspire.hosting/replicaannotation.md) is found.
- [GetResourceDependenciesAsync(IResource, DistributedApplicationExecutionContext, ResourceDependencyDiscoveryMode, CancellationToken)](/reference/api/csharp/aspire.hosting/resourceextensions/methods.md#getresourcedependenciesasync-iresource-distributedapplicationexecutioncontext-resourcedependencydiscoverymode-cancellationtoken) : [Task<IReadOnlySet<IResource>>](/reference/api/csharp/aspire.hosting/iresource.md) `extension` `ats ignored` -- Computes the set of resources that the specified `resource` depends on.
- [GetResourceDependenciesAsync(IResource, DistributedApplicationExecutionContext, ResourceDependencyDiscoveryOptions, CancellationToken)](/reference/api/csharp/aspire.hosting/resourceextensions/methods.md#getresourcedependenciesasync-iresource-distributedapplicationexecutioncontext-resourcedependencydiscoveryoptions-cancellationtoken) : [Task<IReadOnlySet<IResource>>](/reference/api/csharp/aspire.hosting/iresource.md) `extension` `ats ignored` -- Computes the set of resources that the specified `resource` depends on.
- [HasAnnotationIncludingAncestorsOfType(IResource)](/reference/api/csharp/aspire.hosting/resourceextensions/methods.md#hasannotationincludingancestorsoftype-iresource) : `bool` `extension` `ats ignored` -- Gets whether `resource` or its ancestors have an annotation of type `T`
- [HasAnnotationOfType(IResource)](/reference/api/csharp/aspire.hosting/resourceextensions/methods.md#hasannotationoftype-iresource) : `bool` `extension` `ats ignored` -- Gets whether `resource` has an annotation of type `T`
- [IsExcludedFromPublish(IResource)](/reference/api/csharp/aspire.hosting/resourceextensions/methods.md#isexcludedfrompublish-iresource) : `bool` `extension` `ats ignored` -- Gets a value indicating whether the resource is excluded from being published.
- [ProcessArgumentValuesAsync(IResource, DistributedApplicationExecutionContext, Action<object?, string?, Exception?, bool>, ILogger, CancellationToken)](/reference/api/csharp/aspire.hosting/resourceextensions/methods.md#processargumentvaluesasync-iresource-distributedapplicationexecutioncontext-action-object-string-exception-bool-ilogger-cancellationtoken) : `ValueTask` `extension` `obsolete` -- Processes argument values for the specified resource in the given execution context.
- [ProcessEnvironmentVariableValuesAsync(IResource, DistributedApplicationExecutionContext, Action<string, object?, string?, Exception?>, ILogger, CancellationToken)](/reference/api/csharp/aspire.hosting/resourceextensions/methods.md#processenvironmentvariablevaluesasync-iresource-distributedapplicationexecutioncontext-action-string-object-string-exception-ilogger-cancellationtoken) : `ValueTask` `extension` `obsolete` -- Processes environment variable values for the specified resource within the given execution context.
- [RequiresImageBuild(IResource)](/reference/api/csharp/aspire.hosting/resourceextensions/methods.md#requiresimagebuild-iresource) : `bool` `extension` `ats ignored` -- Determines whether the specified resource requires image building.
- [RequiresImageBuildAndPush(IResource)](/reference/api/csharp/aspire.hosting/resourceextensions/methods.md#requiresimagebuildandpush-iresource) : `bool` `extension` `ats ignored` -- Determines whether the specified resource requires image building and pushing.
- [ResolveEndpoints(IResource, IPortAllocator?)](/reference/api/csharp/aspire.hosting/resourceextensions/methods.md#resolveendpoints-iresource-iportallocator) : [IReadOnlyList<ResolvedEndpoint>](/reference/api/csharp/aspire.hosting/resolvedendpoint.md) `extension` `ats ignored` -- 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.
- [TryGetAnnotationsIncludingAncestorsOfType(IResource, IEnumerable<T>)](/reference/api/csharp/aspire.hosting/resourceextensions/methods.md#trygetannotationsincludingancestorsoftype-iresource-ienumerable-t) : `bool` `extension` `ats ignored` -- Attempts to retrieve all annotations of the specified type from the given resource including from parents.
- [TryGetAnnotationsOfType(IResource, IEnumerable<T>)](/reference/api/csharp/aspire.hosting/resourceextensions/methods.md#trygetannotationsoftype-iresource-ienumerable-t) : `bool` `extension` `ats ignored` -- Attempts to retrieve all annotations of the specified type from the given resource.
- [TryGetContainerImageName(IResource, string?)](/reference/api/csharp/aspire.hosting/resourceextensions/methods.md#trygetcontainerimagename-iresource-string) : `bool` `extension` `ats ignored` -- Attempts to get the container image name from the given resource.
- [TryGetContainerImageName(IResource, bool, string?)](/reference/api/csharp/aspire.hosting/resourceextensions/methods.md#trygetcontainerimagename-iresource-bool-string) : `bool` `extension` `ats ignored` -- Attempts to get the container image name from the given resource.
- [TryGetContainerMounts(IResource, IEnumerable<ContainerMountAnnotation>)](/reference/api/csharp/aspire.hosting/resourceextensions/methods.md#trygetcontainermounts-iresource-ienumerable-containermountannotation) : `bool` `extension` `ats ignored` -- Attempts to get the container mounts for the specified resource.
- [TryGetEndpoints(IResource, IEnumerable<EndpointAnnotation>)](/reference/api/csharp/aspire.hosting/resourceextensions/methods.md#trygetendpoints-iresource-ienumerable-endpointannotation) : `bool` `extension` `ats ignored` -- Attempts to retrieve the endpoints for the given resource.
- [TryGetEnvironmentVariables(IResource, IEnumerable<EnvironmentCallbackAnnotation>)](/reference/api/csharp/aspire.hosting/resourceextensions/methods.md#trygetenvironmentvariables-iresource-ienumerable-environmentcallbackannotation) : `bool` `extension` `ats ignored` -- Attempts to get the environment variables from the given resource.
- [TryGetLastAnnotation(IResource, T?)](/reference/api/csharp/aspire.hosting/resourceextensions/methods.md#trygetlastannotation-iresource-t) : `bool` `extension` `ats ignored` -- Attempts to get the last annotation of the specified type from the resource.
- [TryGetUrls(IResource, IEnumerable<ResourceUrlAnnotation>)](/reference/api/csharp/aspire.hosting/resourceextensions/methods.md#trygeturls-iresource-ienumerable-resourceurlannotation) : `bool` `extension` `ats ignored` -- Attempts to retrieve the URLs for the given resource.
- [WithContainerBuildOptions(IResourceBuilder<T>, Action<ContainerBuildOptionsCallbackContext>)](/reference/api/csharp/aspire.hosting/resourceextensions/methods.md#withcontainerbuildoptions-iresourcebuilder-t-action-containerbuildoptionscallbackcontext) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `extension` `experimental` `ats ignored` -- Configures container build options for a compute resource using a callback.
- [WithContainerBuildOptions(IResourceBuilder<T>, Func<ContainerBuildOptionsCallbackContext, Task>)](/reference/api/csharp/aspire.hosting/resourceextensions/methods.md#withcontainerbuildoptions-iresourcebuilder-t-func-containerbuildoptionscallbackcontext-task) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `extension` `experimental` `ats ignored` -- Configures container build options for a compute resource using an async callback.
