# 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/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/Publishing/ManifestPublishingContext.cs#L65-L76)

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/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/Publishing/ManifestPublishingContext.cs#L668-L696)

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/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/Publishing/ManifestPublishingContext.cs#L490-L526)

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/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/Publishing/ManifestPublishingContext.cs#L572-L599)

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/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/Publishing/ManifestPublishingContext.cs#L474-L480)

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/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/Publishing/ManifestPublishingContext.cs#L318-L367)

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/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/Publishing/ManifestPublishingContext.cs#L534-L563)

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.
