Dotnet

Build, test, and publish .NET projects using the dotnet CLI.

Operations

Operation Description
Dotnet.SdkInstall
Install .NET SDK globally in the container. Skips installation if already present (for warm containers). Calling this method disables automatic SDK installation for subsequent operations. Note: Dotnet operations (Build, Test, Restore, Publish) automatically install the SDK if not present.
Dotnet.Project
Creates a reference to a .NET project file (.csproj). Used with Dotnet and Ef operations. The returned ProjectRef has properties: Path, Name, Directory, and Version (reads from csproj).
Dotnet.Restore
Restore NuGet packages for a project. Automatically installs .NET SDK if not present.
Dotnet.Build
Compile a project with optional configuration. Automatically installs .NET SDK if not present.
Dotnet.Test
Run unit tests for a project. Automatically installs .NET SDK if not present.
Dotnet.Publish
Create deployment artifacts with full publish options. Automatically installs .NET SDK if not present.
Dotnet.Tool
Create a reference to a .NET CLI tool for installation.

Operation Details

Dotnet.SdkInstall source

Install .NET SDK globally in the container. Skips installation if already present (for warm containers). Calling this method disables automatic SDK installation for subsequent operations. Note: Dotnet operations (Build, Test, Restore, Publish) automatically install the SDK if not present.

Dotnet.SdkInstall(); // Installs .NET SDK 9.0
Dotnet.SdkInstall("8.0"); // Installs .NET SDK 8.0

Dotnet.Project source

Creates a reference to a .NET project file (.csproj). Used with Dotnet and Ef operations. The returned ProjectRef has properties: Path, Name, Directory, and Version (reads from csproj).

var app = Dotnet.Project("./src/MyApp/MyApp.csproj");
Dotnet.Build(app);
Log.Info($"Building {app.Name} version {app.Version}");

Dotnet.Restore source

Restore NuGet packages for a project. Automatically installs .NET SDK if not present.

Dotnet.Restore(App);
Dotnet.Restore(App, o => o.NoCache = true);

Dotnet.Build source

Compile a project with optional configuration. Automatically installs .NET SDK if not present.

Dotnet.Build(App);
Dotnet.Build(App, o => o.Configuration = Configuration.Release);

Dotnet.Test source

Run unit tests for a project. Automatically installs .NET SDK if not present.

Dotnet.Test(Tests);
Dotnet.Test(Tests, o => o.Filter = "Category=Unit");

Dotnet.Publish source

Create deployment artifacts with full publish options. Automatically installs .NET SDK if not present.

Dotnet.Publish(App);
Dotnet.Publish(App, o => o
  .Output(Root / "dist")
  .WithConfiguration(Configuration.Release)
  .WithRuntime("linux-x64")
  .AsSelfContained()
  .AsSingleFile());

Dotnet.Tool source

Create a reference to a .NET CLI tool for installation.

var efTool = Dotnet.Tool("dotnet-ef");
var efTool = Dotnet.Tool("dotnet-ef", "9.0.0");

Example

Build and publish a .NET application.

// Define project references
var App = Dotnet.Project("./src/App/App.csproj");
var Tests = Dotnet.Project("./tests/App.Tests/App.Tests.csproj");

// Restore, build, and test
Dotnet.Restore(App);
Dotnet.Build(App, o => o.Configuration = Configuration.Release);
Dotnet.Test(Tests);

// Publish as self-contained single file
Dotnet.Publish(App, o => o
  .Output(Root / "dist")
  .WithConfiguration(Configuration.Release)
  .WithRuntime("linux-x64")
  .AsSelfContained()
  .AsSingleFile());

Options Reference

Dotnet.Restore Options

OptionDescription
WithRuntime(string)Set target runtime identifier (e.g., “linux-x64”, “win-x64”, “osx-arm64”). Downloads runtime-specific packages.
NoCacheBypass the NuGet cache, forcing fresh downloads of all packages. Useful when debugging package resolution issues.

Dotnet.Build Options

OptionDescription
ConfigurationBuild configuration: Configuration.Debug or Configuration.Release. Debug includes symbols and disables optimizations. Release enables optimizations for production.
NoRestoreSkip the implicit restore before building. Use when you’ve already run Dotnet.Restore() separately.

Dotnet.Test Options

OptionDescription
ConfigurationBuild configuration for running tests. Tests typically run in Debug for better diagnostics.
NoRestoreSkip restore before testing. Use when dependencies are already restored.
NoBuildSkip build before testing. Use when the project is already built. Implies NoRestore.
FilterTest filter expression to run specific tests. Examples: "Category=Unit", "FullyQualifiedName~MyNamespace", "Name=MyTest".

Dotnet.Publish Options

OptionDescription
Output(path)Output directory for published artifacts. Accepts BuildPath or string.
WithConfiguration(Configuration)Build configuration. Use Configuration.Release for production deployments.
WithRuntime(string)Target runtime identifier. Required for self-contained deployments. Common values: "linux-x64", "linux-arm64", "win-x64", "osx-x64", "osx-arm64".
AsSelfContained(bool)Include the .NET runtime with the application. Creates a standalone deployment that doesn’t require .NET to be installed. Defaults to true when called.
AsSingleFile(bool)Bundle the entire application into a single executable. Makes deployment simpler but increases startup time slightly.
SkipRestore()Skip restore before publishing. Use when dependencies are already restored.
SkipBuild()Skip build before publishing. Use when the project is already built.