Overview
This example demonstrates building a .NET CLI tool installable via dotnet tool install. It publishes self-contained executables for multiple platforms and uses profiles for conditional NuGet publishing.
The workflow performs these steps:
- Installs .NET SDK in the container
- Restores, builds, and tests the project
- Publishes self-contained executables for multiple platforms
- Creates a NuGet package for the dotnet tool
- (with -p publish) Publishes to NuGet.org and deploys docs
- Copies artifacts to the host machine
Build Script
// Define profiles
var publish = DefineProfile("publish");
var project = Dotnet.Project("./src/Ando/Ando.csproj");
var testProject = Dotnet.Project("./tests/Ando.Tests/Ando.Tests.csproj");
var distPath = Root / "dist";
// Build workflow
Dotnet.SdkInstall();
Dotnet.Restore(project);
Dotnet.Build(project);
Dotnet.Test(testProject);
// Publish for multiple platforms
var runtimes = new[] { "win-x64", "linux-x64", "osx-x64", "osx-arm64" };
foreach (var runtime in runtimes)
{
Dotnet.Publish(project, o => o
.WithRuntime(runtime)
.Output(distPath / runtime)
.AsSelfContained()
.AsSingleFile());
}
// Create NuGet package
Nuget.Pack(project);
// Push to NuGet.org (only with -p publish)
if (publish)
{
Nuget.EnsureAuthenticated();
Nuget.Push(project);
Ando.Build(Directory("./website"));
}
// Copy artifacts to host
Ando.CopyArtifactsToHost("dist", "./dist");
Ando.CopyZippedArtifactsToHost("dist", "./dist/binaries.zip");
Using Profiles
This script uses DefineProfile for conditional execution. By default it builds and tests. With the publish profile, it also publishes to NuGet.org.
| Command | Behavior |
|---|---|
ando | Build, test, create NuGet package, copy artifacts |
ando -p publish | All of the above + push to NuGet.org + deploy docs |
Key Operations
| Operation | Purpose |
|---|---|
| DefineProfile() | Creates a profile for conditional execution |
| Dotnet.Publish() | Creates self-contained executables |
| Nuget.Pack() | Creates a NuGet package |
| Nuget.Push() | Publishes to NuGet.org |
| Ando.Build() | Runs a nested build script |
Running the Build
# Build and test only
ando
# Build, test, and push to NuGet.org
ando -p publish