# FoundryExtensions Methods

- Package: [Aspire.Hosting.Foundry](/reference/api/csharp/aspire.hosting.foundry.md)
- Type: [FoundryExtensions](/reference/api/csharp/aspire.hosting.foundry/foundryextensions.md)
- Kind: `Methods`
- Members: `6`

Provides extension methods for adding the Microsoft Foundry resources to the application model.

## AddDeployment(IResourceBuilder<FoundryResource>, string, string, string, string)

- Name: `AddDeployment(IResourceBuilder<FoundryResource>, string, string, string, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<FoundryDeploymentResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Foundry/FoundryExtensions.cs#L61-L81)

Adds and returns a Microsoft Foundry Deployment resource (e.g. an AI model) to the application model.

```csharp
public static class FoundryExtensions
{
    public static IResourceBuilder<FoundryDeploymentResource> AddDeployment(
        this IResourceBuilder<FoundryResource> builder,
        string name,
        string modelName,
        string modelVersion,
        string format)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<FoundryResource>`)
  The Microsoft Foundry resource builder.
- `name` (`string`)
  The name of the Microsoft Foundry Deployment resource.
- `modelName` (`string`)
  The name of the model to deploy.
- `modelVersion` (`string`)
  The version of the model to deploy.
- `format` (`string`)
  The format of the model to deploy.

## Returns

`IResourceBuilder<FoundryDeploymentResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.

## AddDeployment(IResourceBuilder<FoundryResource>, string, FoundryModel)

- Name: `AddDeployment(IResourceBuilder<FoundryResource>, string, FoundryModel)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<FoundryDeploymentResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Foundry/FoundryExtensions.cs#L130-L137)

Adds and returns a Microsoft Foundry Deployment resource to the application model using a [FoundryModel](/reference/api/csharp/aspire.hosting.foundry/foundrymodel.md).

```csharp
public static class FoundryExtensions
{
    public static IResourceBuilder<FoundryDeploymentResource> AddDeployment(
        this IResourceBuilder<FoundryResource> builder,
        string name,
        FoundryModel model)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<FoundryResource>`)
  The Microsoft Foundry resource builder.
- `name` (`string`)
  The name of the Microsoft Foundry Deployment resource.
- `model` ([FoundryModel](/reference/api/csharp/aspire.hosting.foundry/foundrymodel.md))
  The model descriptor, using the [FoundryModel](/reference/api/csharp/aspire.hosting.foundry/foundrymodel.md) class like so:

  ```csharp
  aiFoundry.AddDeployment(name: "chat", model: FoundryModel.OpenAI.Gpt5Mini)
  ```

## Returns

`IResourceBuilder<FoundryDeploymentResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## Remarks

Create a deployment for the OpenAI GTP-5-mini model:

```csharp
var builder = DistributedApplication.CreateBuilder(args);

var aiFoundry = builder.AddFoundry("aiFoundry");
var gpt5mini = aiFoundry.AddDeployment("chat", FoundryModel.OpenAI.Gpt5Mini);
```

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.

## AddFoundry(IDistributedApplicationBuilder, string)

- Name: `AddFoundry(IDistributedApplicationBuilder, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<FoundryResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Foundry/FoundryExtensions.cs#L40-L46)

Adds a Microsoft Foundry resource to the application model.

```csharp
public static class FoundryExtensions
{
    public static IResourceBuilder<FoundryResource> AddFoundry(
        this IDistributedApplicationBuilder builder,
        string name)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
  The `Hosting.IDistributedApplicationBuilder`.
- `name` (`string`)
  The name of the resource. This name will be used as the connection string name when referenced in a dependency.

## Returns

`IResourceBuilder<FoundryResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## RunAsFoundryLocal(IResourceBuilder<FoundryResource>)

- Name: `RunAsFoundryLocal(IResourceBuilder<FoundryResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<FoundryResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Foundry/FoundryExtensions.cs#L166-L201)

Adds a Foundry Local resource to the distributed application builder.

```csharp
public static class FoundryExtensions
{
    public static IResourceBuilder<FoundryResource> RunAsFoundryLocal(
        this IResourceBuilder<FoundryResource> builder)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<FoundryResource>`)
  The distributed application builder.

## Returns

`IResourceBuilder<FoundryResource>` -- A resource builder for the Foundry Local resource.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithProperties(IResourceBuilder<FoundryDeploymentResource>, Action<FoundryDeploymentResource>)

- Name: `WithProperties(IResourceBuilder<FoundryDeploymentResource>, Action<FoundryDeploymentResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<FoundryDeploymentResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Foundry/FoundryExtensions.cs#L150-L155)

Allows setting the properties of a Microsoft Foundry Deployment resource.

```csharp
public static class FoundryExtensions
{
    public static IResourceBuilder<FoundryDeploymentResource> WithProperties(
        this IResourceBuilder<FoundryDeploymentResource> builder,
        Action<FoundryDeploymentResource> configure)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<FoundryDeploymentResource>`)
  The Microsoft Foundry Deployment resource builder.
- `configure` (`Action<FoundryDeploymentResource>`)
  A method that can be used for customizing the [FoundryDeploymentResource](/reference/api/csharp/aspire.hosting.foundry/foundrydeploymentresource.md).

## Returns

`IResourceBuilder<FoundryDeploymentResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithRoleAssignments(IResourceBuilder<T>, IResourceBuilder<FoundryResource>, CognitiveServicesBuiltInRole[])

- Name: `WithRoleAssignments(IResourceBuilder<T>, IResourceBuilder<FoundryResource>, CognitiveServicesBuiltInRole[])`
- Modifiers: `extension`
- Returns: `IResourceBuilder<T>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Foundry/FoundryExtensions.cs)

Assigns the specified roles to the given resource, granting it the necessary permissions on the target Microsoft Foundry resource. This replaces the default role assignments for the resource.

```csharp
public static class FoundryExtensions
{
    public static IResourceBuilder<T> WithRoleAssignments<T>(
        this IResourceBuilder<T> builder,
        IResourceBuilder<FoundryResource> target,
        params CognitiveServicesBuiltInRole[] roles)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<T>`)
  The resource to which the specified roles will be assigned.
- `target` (`IResourceBuilder<FoundryResource>`)
  The target Microsoft Foundry resource.
- `roles` (`CognitiveServicesBuiltInRole[]`)
  The built-in Cognitive Services roles to be assigned.

## Returns

`IResourceBuilder<T>` -- The updated `ApplicationModel.IResourceBuilder`1` with the applied role assignments.

## Remarks

Assigns the CognitiveServicesOpenAIContributor role to the 'Projects.Api' project.

```csharp
var builder = DistributedApplication.CreateBuilder(args);

var aiFoundry = builder.AddFoundry("aiFoundry");

var api = builder.AddProject<Projects.Api>("api")
  .WithRoleAssignments(aiFoundry, CognitiveServicesBuiltInRole.CognitiveServicesOpenAIContributor)
  .WithReference(aiFoundry);
```

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.
