DotnetSdk Operations

Install the .NET SDK in Ubuntu-based containers.

Overview

The DotnetSdk operations allow you to install the .NET SDK globally in Ubuntu-based containers. This is useful when using the default ubuntu:22.04 image, which doesn't include .NET pre-installed.

For warm containers, the installation is skipped if the .NET SDK is already installed at the correct version, making subsequent builds fast.

Note: This is different from the Dotnet operations, which are for running .NET CLI commands like dotnet build and dotnet publish. Use DotnetSdk.Install() first if your container doesn't have .NET installed.

Operations

Operation Description
DotnetSdk.Install
Install .NET SDK globally in the container. Skips installation if already present (for warm containers).
DotnetSdk.Install(); // Installs .NET SDK 9.0
DotnetSdk.Install("8.0"); // Installs .NET SDK 8.0

Example

Build a .NET application on Ubuntu.

build.ando
// Install .NET SDK
DotnetSdk.Install();

// Build the application
var app = Project.From("./src/MyApp/MyApp.csproj");
Dotnet.Restore(app);
Dotnet.Build(app);

Version Support

You can specify the .NET SDK channel version to install:

build.ando
// Install .NET 8.0 (LTS)
DotnetSdk.Install("8.0");

// Install .NET 9.0 (default)
DotnetSdk.Install("9.0");

// Or use default (currently 9.0)
DotnetSdk.Install();