# ExecutableResourceBuilderExtensions Methods

- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Type: [ExecutableResourceBuilderExtensions](/reference/api/csharp/aspire.hosting/executableresourcebuilderextensions.md)
- Kind: `Methods`
- Members: `7`

Provides extension methods for adding executable resources to the [IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md) application model.

## AddExecutable(IDistributedApplicationBuilder, string, string, string, string[]?)

- Name: `AddExecutable(IDistributedApplicationBuilder, string, string, string, string[]?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<ExecutableResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ExecutableResourceBuilderExtensions.cs)

Adds an executable resource to the application model.

```csharp
public static class ExecutableResourceBuilderExtensions
{
    public static IResourceBuilder<ExecutableResource> AddExecutable(
        this IDistributedApplicationBuilder builder,
        string name,
        string command,
        string workingDirectory,
        params string[]? args)
    {
        // ...
    }
}
```

## 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.
- `command` (`string`)
  The executable path. This can be a fully qualified path or a executable to run from the shell/command line.
- `workingDirectory` (`string`)
  The working directory of the executable.
- `args` (`string[]?`)
  The arguments to the executable.

## Returns

`IResourceBuilder<ExecutableResource>` -- The `ApplicationModel.IResourceBuilder`1`.

## Remarks

You can run any executable command using its full path. As a security feature, Aspire doesn't run executable unless the command is located in a path listed in the PATH environment variable. To run an executable file that's in the current directory, specify the full path or use the relative path `./` to represent the current directory.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddExecutable(IDistributedApplicationBuilder, string, string, string, object[]?)

- Name: `AddExecutable(IDistributedApplicationBuilder, string, string, string, object[]?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<ExecutableResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ExecutableResourceBuilderExtensions.cs)

Adds an executable resource to the application model.

```csharp
public static class ExecutableResourceBuilderExtensions
{
    public static IResourceBuilder<ExecutableResource> AddExecutable(
        this IDistributedApplicationBuilder builder,
        string name,
        string command,
        string workingDirectory,
        params object[]? args)
    {
        // ...
    }
}
```

## 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.
- `command` (`string`)
  The executable path. This can be a fully qualified path or a executable to run from the shell/command line.
- `workingDirectory` (`string`)
  The working directory of the executable.
- `args` (`object[]?`)
  The arguments to the executable.

## Returns

`IResourceBuilder<ExecutableResource>` -- The `ApplicationModel.IResourceBuilder`1`.

## Remarks

This method is not available in polyglot app hosts. Use the string[] overload instead.

## ATS metadata

### Ignored by ATS

- Reason: Uses object[] parameter which is not ATS-compatible. String[] overload is exported.

## PublishAsDockerFile(IResourceBuilder<T>)

- Name: `PublishAsDockerFile(IResourceBuilder<T>)`
- 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/ExecutableResourceBuilderExtensions.cs#L80)

Adds annotation to [ExecutableResource](/reference/api/csharp/aspire.hosting/executableresource.md) to support containerization during deployment.

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

## Parameters

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

## Returns

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

## ATS metadata

### Ignored by ATS

- Reason: Polyglot app hosts use the overload with the optional configure callback.

## PublishAsDockerFile(IResourceBuilder<T>, IEnumerable<DockerBuildArg>)

> **Obsolete:** Use builder.PublishAsDockerFile(c => c.WithBuildArg(name, value)) instead.

- Name: `PublishAsDockerFile(IResourceBuilder<T>, IEnumerable<DockerBuildArg>)`
- 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/ExecutableResourceBuilderExtensions.cs#L95-L103)

Adds annotation to [ExecutableResource](/reference/api/csharp/aspire.hosting/executableresource.md) to support containerization during deployment. The resulting container image is built, and when the optional `buildArgs` are provided they're used with `docker build --build-arg`.

```csharp
public static class ExecutableResourceBuilderExtensions
{
    public static IResourceBuilder<T> PublishAsDockerFile<T>(
        this IResourceBuilder<T> builder,
        IEnumerable<DockerBuildArg>? buildArgs)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md))
  Resource builder
- `buildArgs` ([IEnumerable<DockerBuildArg>](/reference/api/csharp/aspire.hosting/dockerbuildarg.md))
  The optional build arguments, used with `docker build --build-args`.

## Returns

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

## 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/ExecutableResourceBuilderExtensions.cs#L124-L166)

Adds support for containerizing this [ExecutableResource](/reference/api/csharp/aspire.hosting/executableresource.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 ExecutableResourceBuilderExtensions
{
    public static IResourceBuilder<T> PublishAsDockerFile<T>(
        this IResourceBuilder<T> builder,
        Action<IResourceBuilder<ContainerResource>>? configure)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md))
  Resource builder
- `configure` (`Action<IResourceBuilder<ContainerResource>>`)
  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 executable 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

- Available to Polyglot AppHosts through the Aspire Type System.
- Synchronous exports run on a background thread.

## WithCommand(IResourceBuilder<T>, string)

- Name: `WithCommand(IResourceBuilder<T>, string)`
- 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/ExecutableResourceBuilderExtensions.cs#L179-L196)

Sets the command for the executable resource.

```csharp
public static class ExecutableResourceBuilderExtensions
{
    public static IResourceBuilder<T> WithCommand<T>(
        this IResourceBuilder<T> builder,
        string command)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md))
  Builder for the executable resource.
- `command` (`string`)
  Command.

## Returns

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

## ATS metadata

### ATS export

- Capability ID: `Aspire.Hosting/withExecutableCommand`

## WithWorkingDirectory(IResourceBuilder<T>, string)

- Name: `WithWorkingDirectory(IResourceBuilder<T>, string)`
- 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/ExecutableResourceBuilderExtensions.cs#L209-L218)

Sets the working directory for the executable resource.

```csharp
public static class ExecutableResourceBuilderExtensions
{
    public static IResourceBuilder<T> WithWorkingDirectory<T>(
        this IResourceBuilder<T> builder,
        string workingDirectory)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md))
  Builder for the executable resource.
- `workingDirectory` (`string`)
  Working directory.

## Returns

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

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.
