# WithEnvironment

- Module: [Aspire.Hosting](/reference/api/go/aspire.hosting.md)
- Version: `17.0.0`
- Kind: `method`
- Defined on: [`ResourceWithEnvironment`](/reference/api/go/aspire.hosting/resourcewithenvironment.md)
- Source: [GitHub](https://github.com/microsoft/aspire/tree/2d325b13709752ba6d9a943635c5e2940a2530c0)

Sets an environment variable

## Definition

```go
func (ResourceWithEnvironment) WithEnvironment(
    name string,
    value any,
) ResourceWithEnvironment
```

## Parameters

- `name` (`string`)
- `value` (`any`)

## Returns

[`ResourceWithEnvironment`](/reference/api/go/aspire.hosting/resourcewithenvironment.md)

Returns a handle; failures surface later via `Err()`.

## Applies to

- [`CSharpAppResource`](/reference/api/go/aspire.hosting/csharpappresource.md)
- [`ContainerResource`](/reference/api/go/aspire.hosting/containerresource.md)
- [`DotnetToolResource`](/reference/api/go/aspire.hosting/dotnettoolresource.md)
- [`ExecutableResource`](/reference/api/go/aspire.hosting/executableresource.md)
- [`ProjectResource`](/reference/api/go/aspire.hosting/projectresource.md)
