# ContainerFilesExtensions Methods

- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Type: [ContainerFilesExtensions](/reference/api/csharp/aspire.hosting/containerfilesextensions.md)
- Kind: `Methods`
- Members: `2`

Provides Dockerfile builder extension methods for supporting [ResourceBuilderExtensions.PublishWithContainerFiles(IResourceBuilder<T>, IResourceBuilder<IResourceWithContainerFiles>, string)](/reference/api/csharp/aspire.hosting/resourcebuilderextensions/methods.md#publishwithcontainerfiles-iresourcebuilder-t-iresourcebuilder-iresourcewithcontainerfiles-string).

## AddContainerFiles(DockerfileStage, IResource, string, ILogger?)

> **Experimental:** ASPIREDOCKERFILEBUILDER001 - [Learn more](/diagnostics/aspiredockerfilebuilder001/)

- Name: `AddContainerFiles(DockerfileStage, IResource, string, ILogger?)`
- Modifiers: `extension`
- Returns: [DockerfileStage](/reference/api/csharp/aspire.hosting/dockerfilestage.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/Docker/ContainerFilesExtensions.cs#L84-L119)

Adds COPY --from statements to the Dockerfile stage for container files from resources referenced by [ContainerFilesDestinationAnnotation](/reference/api/csharp/aspire.hosting/containerfilesdestinationannotation.md).

```csharp
public static class ContainerFilesExtensions
{
    public static DockerfileStage AddContainerFiles(
        this DockerfileStage stage,
        IResource resource,
        string rootDestinationPath,
        ILogger? logger)
    {
        // ...
    }
}
```

## Parameters

- `stage` ([DockerfileStage](/reference/api/csharp/aspire.hosting/dockerfilestage.md))
  The Dockerfile stage to add container file copy statements to.
- `resource` ([IResource](/reference/api/csharp/aspire.hosting/iresource.md))
  The resource that may have [ContainerFilesDestinationAnnotation](/reference/api/csharp/aspire.hosting/containerfilesdestinationannotation.md) annotations specifying files to copy.
- `rootDestinationPath` (`string`)
  The root destination path in the container. Relative paths in annotations will be appended to this path.
- `logger` (`ILogger?`)
  The logger used for logging information or errors.

## Returns

[DockerfileStage](/reference/api/csharp/aspire.hosting/dockerfilestage.md) -- The [DockerfileStage](/reference/api/csharp/aspire.hosting/dockerfilestage.md) to allow for fluent chaining.

## Remarks

This method processes all [ContainerFilesDestinationAnnotation](/reference/api/csharp/aspire.hosting/containerfilesdestinationannotation.md) annotations on the resource and generates COPY --from statements for each source container's files.

For each annotation:

- If the source resource has a container image name (via `TryGetContainerImageName`), COPY statements are generated
- If the source resource does not have a container image name, it is skipped
- Relative destination paths are combined with `rootDestinationPath`
- Absolute destination paths are used as-is
- Each [ContainerFilesSourceAnnotation](/reference/api/csharp/aspire.hosting/containerfilessourceannotation.md) on the source resource generates a COPY statement

This is typically used when building container images that need to include files from other containers, such as copying static assets from a frontend build container into a backend API container.

## ATS metadata

### Ignored by ATS

- Reason: Polyglot-facing wrappers are exported from DockerfileBuilderExports with a curated signature.

## AddContainerFilesStages(DockerfileBuilder, IResource, ILogger?)

> **Experimental:** ASPIREDOCKERFILEBUILDER001 - [Learn more](/diagnostics/aspiredockerfilebuilder001/)

- Name: `AddContainerFilesStages(DockerfileBuilder, IResource, ILogger?)`
- Modifiers: `extension`
- Returns: [DockerfileBuilder](/reference/api/csharp/aspire.hosting/dockerfilebuilder.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/Docker/ContainerFilesExtensions.cs#L26-L49)

Adds Dockerfile instructions to include container files from the specified resource into the Dockerfile build process.

```csharp
public static class ContainerFilesExtensions
{
    public static DockerfileBuilder AddContainerFilesStages(
        this DockerfileBuilder builder,
        IResource resource,
        ILogger? logger)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([DockerfileBuilder](/reference/api/csharp/aspire.hosting/dockerfilebuilder.md))
  The Dockerfile builder to which container file instructions will be added. Cannot be null.
- `resource` ([IResource](/reference/api/csharp/aspire.hosting/iresource.md))
  The resource containing container files to be added to the Dockerfile. Cannot be null.
- `logger` (`ILogger?`)
  An optional logger used to record warnings if container image names cannot be determined for source resources.

## Returns

[DockerfileBuilder](/reference/api/csharp/aspire.hosting/dockerfilebuilder.md) -- The same DockerfileBuilder instance with additional instructions for container files, enabling method chaining.

## ATS metadata

### Ignored by ATS

- Reason: Polyglot-facing wrappers are exported from DockerfileBuilderExports with a curated signature.
