CommunityToolkit.Aspire.Hosting.Golang 13.2.1-beta.532

Prefix Reserved
This is a prerelease version of CommunityToolkit.Aspire.Hosting.Golang.
There is a newer version of this package available.
See the version list below for details.
dotnet add package CommunityToolkit.Aspire.Hosting.Golang --version 13.2.1-beta.532
                    
NuGet\Install-Package CommunityToolkit.Aspire.Hosting.Golang -Version 13.2.1-beta.532
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CommunityToolkit.Aspire.Hosting.Golang" Version="13.2.1-beta.532" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CommunityToolkit.Aspire.Hosting.Golang" Version="13.2.1-beta.532" />
                    
Directory.Packages.props
<PackageReference Include="CommunityToolkit.Aspire.Hosting.Golang" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CommunityToolkit.Aspire.Hosting.Golang --version 13.2.1-beta.532
                    
#r "nuget: CommunityToolkit.Aspire.Hosting.Golang, 13.2.1-beta.532"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CommunityToolkit.Aspire.Hosting.Golang@13.2.1-beta.532
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CommunityToolkit.Aspire.Hosting.Golang&version=13.2.1-beta.532&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=CommunityToolkit.Aspire.Hosting.Golang&version=13.2.1-beta.532&prerelease
                    
Install as a Cake Tool

CommunityToolkit.Aspire.Hosting.Golang library

Provides extensions methods and resource definitions for the Aspire AppHost to support running Golang applications.

Getting Started

Install the package

In your AppHost project, install the package using the following command:

dotnet add package CommunityToolkit.Aspire.Hosting.Golang

Example usage

Then, in the Program.cs file of AppHost, define a Golang resource, then call AddGolangApp:

var golang = builder.AddGolangApp("golang", "../gin-api")
    .WithHttpEndpoint(env: "PORT");

The PORT environment variable is used to determine the port the Golang application should listen on. It is randomly assigned by the Aspire. The name of the environment variable can be changed by passing a different value to the WithHttpEndpoint method.

To have the Golang application listen on the correct port, you can use the following code in your Golang application:

r.Run(":"+os.Getenv("PORT"))

Dependency Management

The integration provides support for Go module dependency management using go mod tidy or go mod download.

Using go mod tidy

To run go mod tidy before your application starts (to clean up and verify dependencies):

var golang = builder.AddGolangApp("golang", "../gin-api")
    .WithGoModTidy()
    .WithHttpEndpoint(env: "PORT");

By default, WithGoModTidy() runs go mod tidy before the application starts (equivalent to install: true). You can set install: false to create the installer resource but require explicit start:

var golang = builder.AddGolangApp("golang", "../gin-api")
    .WithGoModTidy(install: false)  // Installer created but requires explicit start
    .WithHttpEndpoint(env: "PORT");

Using go mod download

To run go mod download before your application starts (to download dependencies without verification):

var golang = builder.AddGolangApp("golang", "../gin-api")
    .WithGoModDownload()
    .WithHttpEndpoint(env: "PORT");

Similarly, you can control the installer behavior:

var golang = builder.AddGolangApp("golang", "../gin-api")
    .WithGoModDownload(install: false)  // Installer created but requires explicit start
    .WithHttpEndpoint(env: "PORT");

When install is true (default), the installer resource is created and the Go application waits for it to complete before starting. When install is false, the installer resource is still created but is set to require explicit start, appearing in the Aspire dashboard but not automatically executing.

You can also customize the installer resource using the optional configureInstaller parameter:

var golang = builder.AddGolangApp("golang", "../gin-api")
    .WithGoModTidy(configureInstaller: installer =>
    {
        installer.WithEnvironment("GOPROXY", "https://proxy.golang.org,direct");
    })
    .WithHttpEndpoint(env: "PORT");

Note: The WithGoModTidy and WithGoModDownload methods only create installer resources in run mode (when the application is started locally). They do not run when publishing, as the generated Dockerfile handles dependency management automatically.

Publishing

When publishing your Aspire application, the Golang resource automatically generates a multi-stage Dockerfile for containerization. This means you don't need to manually create a Dockerfile for your Golang application.

Automatic Version Detection

The integration automatically detects the Go version to use by:

  1. Checking the go.mod file for the Go version directive
  2. Falling back to the installed Go toolchain version
  3. Using Go 1.23 as the default if no version is detected

Customizing Base Images

You can customize the base images used in the Dockerfile:

var golang = builder.AddGolangApp("golang", "../gin-api")
    .WithHttpEndpoint(env: "PORT")
    .WithDockerfileBaseImage(
        buildImage: "golang:1.22-alpine",
        runtimeImage: "alpine:3.20");

Container Files Support

The Golang resource supports copying files from other resources into the container during publishing. This is useful for serving static frontend files from your Go application. The resource implements IContainerFilesDestinationResource with a default destination of /app/static.

To copy files from another resource (such as a frontend build) into your Golang container, use the WithContainerFiles method:

var frontend = builder.AddViteApp("frontend", "./frontend");

var golang = builder.AddGolangApp("golang", "../gin-api")
    .WithHttpEndpoint(env: "PORT")
    .WithContainerFiles("/app/static", frontend.Resource);

This will copy the output files from the frontend resource into the /app/static directory in the Golang container when publishing. Note: WithContainerFiles is provided by the Aspire framework when the resource implements IContainerFilesDestinationResource and may require additional using directives (for example, using Aspire.Hosting;).

Generated Dockerfile

The automatically generated Dockerfile:

  • Uses the detected or default Go version (e.g., golang:1.22) as the build stage
  • Uses alpine:3.21 as the runtime stage for a smaller final image
  • Installs CA certificates in the runtime image for HTTPS support
  • Respects your build tags if specified
  • Builds the executable specified in your AddGolangApp call

This automatic Dockerfile generation happens when you publish your Aspire application and requires no additional configuration.

Additional Information

https://learn.microsoft.com/dotnet/aspire/community-toolkit/hosting-golang

Feedback & contributing

https://github.com/CommunityToolkit/Aspire

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
13.4.0 449 6/2/2026 13.4.0 is deprecated because it is no longer maintained.
13.4.0-beta.654 0 6/18/2026
13.4.0-beta.651 36 6/17/2026
13.3.0 947 5/14/2026
13.2.1-beta.604 50 5/14/2026
13.2.1-beta.532 192 3/13/2026
13.2.1-beta.531 76 3/11/2026
13.2.1-beta.528 69 3/5/2026
13.1.2-beta.518 102 2/17/2026
13.1.2-beta.516 96 2/9/2026
13.1.2-beta.515 82 2/2/2026
13.1.2-beta.514 113 1/30/2026
13.1.2-beta.513 79 1/29/2026
13.1.2-beta.512 79 1/29/2026
13.1.2-beta.511 81 1/28/2026
13.1.2-beta.509 73 1/20/2026
13.1.2-beta.508 75 1/19/2026
13.1.2-beta.507 77 1/19/2026
13.1.2-beta.506 87 1/16/2026
13.1.2-beta.505 74 1/16/2026
Loading failed