# ManifestPublishingContext Methods

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

Contextual information used for manifest publishing during this execution of the AppHost.

## GetManifestRelativePath(string?)

- Name: `GetManifestRelativePath(string?)`
- Modifiers: `nullable`
- Returns: `string?`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/a3766e994fd2cba86c8ac60b8a80268cab7e6383/src/Aspire.Hosting/Publishing/ManifestPublishingContext.cs#L64-L75)

Generates a relative path based on the location of the manifest path.

```csharp
public sealed class ManifestPublishingContext
{
    public string? GetManifestRelativePath(
        string? path)
    {
        // ...
    }
}
```

## Parameters

- `path` (`string?`)
  A path to a file.

## Returns

`string?` -- The specified path as a relative path to the manifest.

## Exceptions

- [DistributedApplicationException](/reference/api/csharp/aspire.hosting/distributedapplicationexception.md) -- Throws when could not get the directory directory name from the output path.

## TryAddDependentResources(object?)

- Name: `TryAddDependentResources(object?)`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/a3766e994fd2cba86c8ac60b8a80268cab7e6383/src/Aspire.Hosting/Publishing/ManifestPublishingContext.cs#L669-L697)

Ensures that any [IResource](/reference/api/csharp/aspire.hosting/iresource.md) instances referenced by `value` are written to the manifest.

```csharp
public sealed class ManifestPublishingContext
{
    public void TryAddDependentResources(
        object? value)
    {
        // ...
    }
}
```

## Parameters

- `value` (`object?`)
  The object to check for references that may be resources that need to be written.

## WriteBindings(IResource)

- Name: `WriteBindings(IResource)`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/a3766e994fd2cba86c8ac60b8a80268cab7e6383/src/Aspire.Hosting/Publishing/ManifestPublishingContext.cs#L491-L527)

Writes endpoints to the resource entry in the manifest based on the resource's [EndpointAnnotation](/reference/api/csharp/aspire.hosting/endpointannotation.md) entries in the [IResource.Annotations](/reference/api/csharp/aspire.hosting/iresource/properties.md#annotations) collection.

```csharp
public sealed class ManifestPublishingContext
{
    public void WriteBindings(
        IResource resource)
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResource](/reference/api/csharp/aspire.hosting/iresource.md))
  The [IResource](/reference/api/csharp/aspire.hosting/iresource.md) that contains [EndpointAnnotation](/reference/api/csharp/aspire.hosting/endpointannotation.md) annotations.

## WriteCommandLineArgumentsAsync(IResource)

- Name: `WriteCommandLineArgumentsAsync(IResource)`
- Returns: `Task`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/a3766e994fd2cba86c8ac60b8a80268cab7e6383/src/Aspire.Hosting/Publishing/ManifestPublishingContext.cs#L573-L600)

Writes command line arguments to the manifest based on the [IResource](/reference/api/csharp/aspire.hosting/iresource.md) resource's [CommandLineArgsCallbackAnnotation](/reference/api/csharp/aspire.hosting/commandlineargscallbackannotation.md) annotations.

```csharp
public sealed class ManifestPublishingContext
{
    public Task WriteCommandLineArgumentsAsync(
        IResource resource)
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResource](/reference/api/csharp/aspire.hosting/iresource.md))
  The [IResource](/reference/api/csharp/aspire.hosting/iresource.md) that contains [CommandLineArgsCallbackAnnotation](/reference/api/csharp/aspire.hosting/commandlineargscallbackannotation.md) annotations.

## Returns

`Task` -- The `Tasks.Task` to await for completion.

## WriteConnectionString(IResource)

- Name: `WriteConnectionString(IResource)`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/a3766e994fd2cba86c8ac60b8a80268cab7e6383/src/Aspire.Hosting/Publishing/ManifestPublishingContext.cs#L475-L481)

Writes the "connectionString" field for the underlying resource.

```csharp
public sealed class ManifestPublishingContext
{
    public void WriteConnectionString(
        IResource resource)
    {
        // ...
    }
}
```

## Parameters

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

## WriteContainerAsync(ContainerResource)

- Name: `WriteContainerAsync(ContainerResource)`
- Returns: `Task`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/a3766e994fd2cba86c8ac60b8a80268cab7e6383/src/Aspire.Hosting/Publishing/ManifestPublishingContext.cs#L317-L366)

Writes JSON elements to the manifest which represent a container resource.

```csharp
public sealed class ManifestPublishingContext
{
    public Task WriteContainerAsync(
        ContainerResource container)
    {
        // ...
    }
}
```

## Parameters

- `container` ([ContainerResource](/reference/api/csharp/aspire.hosting/containerresource.md))
  The container resource to written to the manifest.

## Exceptions

- [DistributedApplicationException](/reference/api/csharp/aspire.hosting/distributedapplicationexception.md) -- Thrown if the container resource does not contain a [ContainerImageAnnotation](/reference/api/csharp/aspire.hosting/containerimageannotation.md).

## WriteEnvironmentVariablesAsync(IResource)

- Name: `WriteEnvironmentVariablesAsync(IResource)`
- Returns: `Task`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/a3766e994fd2cba86c8ac60b8a80268cab7e6383/src/Aspire.Hosting/Publishing/ManifestPublishingContext.cs#L535-L564)

Writes environment variables to the manifest base on the [IResource](/reference/api/csharp/aspire.hosting/iresource.md) resource's [EnvironmentCallbackAnnotation](/reference/api/csharp/aspire.hosting/environmentcallbackannotation.md) annotations."/>

```csharp
public sealed class ManifestPublishingContext
{
    public Task WriteEnvironmentVariablesAsync(
        IResource resource)
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResource](/reference/api/csharp/aspire.hosting/iresource.md))
  The [IResource](/reference/api/csharp/aspire.hosting/iresource.md) which contains [EnvironmentCallbackAnnotation](/reference/api/csharp/aspire.hosting/environmentcallbackannotation.md) annotations.
