Operations
| Operation | Description |
|---|---|
Root | The root path of the project (where build.csando is located). Returns BuildPath, not DirectoryRef. Use for path construction and string arguments. For operations requiring DirectoryRef (Npm, Cloudflare, etc.), use Directory(".") instead. Supports path combining with the / operator. |
Temp | Temporary files directory (root/.ando/tmp). Supports path combining with the / operator. Use for caches, intermediate files, etc. |
Secrets.UserSecrets | Reads secrets.json of a .NET user secrets store on the host while the script is evaluated, without calling dotnet. It is not a step. Signature: Secrets.UserSecrets(string userSecretsIdOrProjectPath). The path is ~/.microsoft/usersecrets/<id>/secrets.json on Linux and macOS, %APPDATA%\Microsoft\UserSecrets\<id>\secrets.json on Windows. Pass the UserSecretsId, or a .csproj (or a folder with exactly one) to read the id from it; relative paths resolve against the directory you ran ando from. Nested objects are flattened with : (Deploy:Azure:ClientSecret); flat "A:B" keys work too. Returns a read-only set with an indexer that throws an error naming the missing key (never a value) and TryGet(key, out value). A value is registered for redaction when the script reads it (indexer or TryGet); read config through the set only if it is secret, because a plain value such as Region is not redacted unless it was read this way. Each line of a multi-line value is also redacted on its own. See Secrets. |
Secrets.EnvFile | Reads the named keys from a dotenv file on the host while the script is evaluated (same format as .env.ando; use a separate file such as .env.secrets). Not a step. Signature: Secrets.EnvFile(string path, params string[] keys). Relative paths resolve against the directory you ran ando from. A missing key fails at evaluation. A file inside a git repository that is not gitignored fails at evaluation. The values are registered for redaction. The values are not set in the process environment and not added to ANDO_LOADED_ENV_KEYS, so this call does not forward them to container commands; pass them to the operation that needs them (for example Cloudflare.UseCredentials). .env.ando (or .env) is still loaded and forwarded to every container command by the normal env loading unless the run uses --no-env; reading it here logs a warning that its keys are forwarded anyway. Returns the same read-only set as Secrets.UserSecrets. |
Env | Gets an environment variable. Global function — call as Env(), not Ando.Env(). Signature: Env(string name, bool required = true, bool secret = false). By default throws if not set. Pass required: false to return null. The second parameter is a bool, not a default value — use null-coalescing (??) for defaults. The value is registered for redaction (console, build.csando.log, run records and --dry-run) when the name looks secret (_TOKEN, _SECRET, _PASSWORD, _KEY and similar) or when you pass secret: true. Values shorter than 6 characters are never redacted. |
Directory | Creates a DirectoryRef — required by operations that need a working directory (Npm, Cloudflare, Playwright, Ando.Build). Global function — call as Directory(). Note: Root returns BuildPath, not DirectoryRef. Use Directory(".") when an operation needs a reference to the project root. Supports path combining with the / operator. |
DefineProfile | Defines a build profile that can be activated via CLI. Takes a single argument (the profile name). Returns a Profile object with implicit bool conversion — use directly in if statements. There is no HasProfile() or Profile() function. Use -p or --profile CLI flag to activate. |
Log | Logging operations for outputting messages during the build. Has four methods: Log.Info() (visible at Normal verbosity), Log.Warning() (visible at Minimal+), Log.Error() (always visible), and Log.Debug() (only at Detailed verbosity). |
Operation Details
Root
source
The root path of the project (where build.csando is located). Returns BuildPath, not DirectoryRef. Use for path construction and string arguments. For operations requiring DirectoryRef (Npm, Cloudflare, etc.), use Directory(".") instead. Supports path combining with the / operator.
var output = Root / "dist";
Dotnet.Publish(app, o => o.Output(output));Temp
source
Temporary files directory (root/.ando/tmp). Supports path combining with the / operator. Use for caches, intermediate files, etc.
var cache = Temp / "cache";
var intermediate = Temp / "build-output";Secrets.UserSecrets
source
Reads secrets.json of a .NET user secrets store on the host while the script is evaluated, without calling dotnet. It is not a step. Signature: Secrets.UserSecrets(string userSecretsIdOrProjectPath). The path is ~/.microsoft/usersecrets/<id>/secrets.json on Linux and macOS, %APPDATA%\Microsoft\UserSecrets\<id>\secrets.json on Windows. Pass the UserSecretsId, or a .csproj (or a folder with exactly one) to read the id from it; relative paths resolve against the directory you ran ando from. Nested objects are flattened with : (Deploy:Azure:ClientSecret); flat "A:B" keys work too. Returns a read-only set with an indexer that throws an error naming the missing key (never a value) and TryGet(key, out value). A value is registered for redaction when the script reads it (indexer or TryGet); read config through the set only if it is secret, because a plain value such as Region is not redacted unless it was read this way. Each line of a multi-line value is also redacted on its own. See Secrets.
var sp = Secrets.UserSecrets("simplesign365-dev");
var clientSecret = sp["Deploy:Azure:ClientSecret"]; // redacted in all output
var sp = Secrets.UserSecrets("src/App/App.csproj");Secrets.EnvFile
source
Reads the named keys from a dotenv file on the host while the script is evaluated (same format as .env.ando; use a separate file such as .env.secrets). Not a step. Signature: Secrets.EnvFile(string path, params string[] keys). Relative paths resolve against the directory you ran ando from. A missing key fails at evaluation. A file inside a git repository that is not gitignored fails at evaluation. The values are registered for redaction. The values are not set in the process environment and not added to ANDO_LOADED_ENV_KEYS, so this call does not forward them to container commands; pass them to the operation that needs them (for example Cloudflare.UseCredentials). .env.ando (or .env) is still loaded and forwarded to every container command by the normal env loading unless the run uses --no-env; reading it here logs a warning that its keys are forwarded anyway. Returns the same read-only set as Secrets.UserSecrets.
var cf = Secrets.EnvFile(".env.secrets", "CLOUDFLARE_API_TOKEN", "CLOUDFLARE_ACCOUNT_ID");
Cloudflare.UseCredentials(cf["CLOUDFLARE_API_TOKEN"], cf["CLOUDFLARE_ACCOUNT_ID"]);Env
source
Gets an environment variable. Global function — call as Env(), not Ando.Env(). Signature: Env(string name, bool required = true, bool secret = false). By default throws if not set. Pass required: false to return null. The second parameter is a bool, not a default value — use null-coalescing (??) for defaults. The value is registered for redaction (console, build.csando.log, run records and --dry-run) when the name looks secret (_TOKEN, _SECRET, _PASSWORD, _KEY and similar) or when you pass secret: true. Values shorter than 6 characters are never redacted.
var apiKey = Env("API_KEY");
var optional = Env("OPTIONAL_VAR", required: false);
var lang = Env("SITE_LANG", required: false) ?? "en";
var accountId = Env("CLOUDFLARE_ACCOUNT_ID", secret: true); // name does not look secret, value is redacted anywayDirectory
source
Creates a DirectoryRef — required by operations that need a working directory (Npm, Cloudflare, Playwright, Ando.Build). Global function — call as Directory(). Note: Root returns BuildPath, not DirectoryRef. Use Directory(".") when an operation needs a reference to the project root. Supports path combining with the / operator.
var frontend = Directory("./frontend");
Npm.Ci(frontend);
Cloudflare.PagesDeploy(frontend / "dist", "my-site");
Npm.Ci(Directory(".")); // Use Directory(".") instead of RootDefineProfile
source
Defines a build profile that can be activated via CLI. Takes a single argument (the profile name). Returns a Profile object with implicit bool conversion — use directly in if statements. There is no HasProfile() or Profile() function. Use -p or --profile CLI flag to activate.
var release = DefineProfile("release");
var publish = DefineProfile("publish");
Dotnet.Build(app);
if (release) {
Git.Tag("v1.0.0");
GitHub.CreateRelease(o => o.WithTag("v1.0.0"));
}
// CLI usage:
// ando -p release
// ando -p publish,releaseLog
source
Logging operations for outputting messages during the build. Has four methods: Log.Info() (visible at Normal verbosity), Log.Warning() (visible at Minimal+), Log.Error() (always visible), and Log.Debug() (only at Detailed verbosity).
Log.Info("Starting deployment...");
Log.Warning("Cache is stale, rebuilding");
Log.Error("Failed to connect to server");
Log.Debug("Processing item 5 of 10");Overview
These names are available in every build.csando script without a prefix or import. They are not members of the Ando object: write Env("API_KEY"), not Ando.Env("API_KEY"). The operations of the Ando object (Ando.UseImage, Ando.Block and so on) are on the Ando page.
| Global | Kind | Description |
|---|---|---|
Root | BuildPath | Project root (where build.csando is). Supports the / operator. |
Temp | BuildPath | Temporary directory (.ando/tmp). Supports the / operator. |
Directory() | function | Creates a DirectoryRef. |
Env() | function | Reads an environment variable. |
Secrets | operations object | Secrets.UserSecrets, Secrets.EnvFile. See Secrets. |
DefineProfile() | function | Defines a build profile and returns a Profile. |
Log | operations object | Log.Info, Log.Warning, Log.Error, Log.Debug. |
The other globals are the operation objects, one per provider: Ando, AppService, Archive, Azure, Bicep, Bun, Cloudflare, Docfx, Docker, Dotnet, Ef, Files, Functions, Git, GitHub, Http, Node, Npm, Nuget, Playwright, Secrets and Shell.
Globals are evaluated while the script loads. Env(), Directory(), DefineProfile(), Root and Temp do not register steps. Log.* calls are steps: they print when their turn in the step order comes.
Examples
These globals are available in all build.csando scripts without any prefix or import. Env(), Directory(), and DefineProfile() are global functions — call them directly, not as methods on the Ando object.
// Directory reference (returns DirectoryRef)
var frontend = Directory("./frontend");
// Path construction with / operator (Root returns BuildPath)
var output = Root / "dist";
var cache = Temp / "build-cache";
// Access environment variables (global function, not Ando.Env)
var dbUrl = Env("DATABASE_URL");
var apiKey = Env("API_KEY", required: false);
var accountId = Env("ACCOUNT_ID", secret: true); // redact a value whose name does not look secret
var lang = Env("SITE_LANG", required: false) ?? "en";
// Use regular C# variables for custom values
var buildNumber = "123";
Environment Variables
The Env() function retrieves environment variables. The second parameter is required: (a bool), NOT a default value string.
// Required (default) - throws if not set
var apiKey = Env("API_KEY");
// Optional - returns null if not set
var optional = Env("OPTIONAL_VAR", required: false);
// Optional with default value - use null-coalescing (??)
var lang = Env("SITE_LANG", required: false) ?? "en";
// WRONG: second parameter is bool, not a default value
// var lang = Env("SITE_LANG", "en"); // Compile error!
There is no SetEnv() function. Set environment variables via .env.ando files, OS environment, or CI/CD configuration.
Secrets
Secrets are redacted by value: once a value is registered, ANDO replaces it with [REDACTED] in console output, build.csando.log, run records and --dry-run step trees. Values shorter than 6 characters are never redacted.
Env(name)registers the value when the name looks secret (*_TOKEN,*_SECRET,*_PASSWORD,*_KEYand similar). Passsecret: trueto register any other value:Env("CLOUDFLARE_ACCOUNT_ID", secret: true).Secrets.UserSecrets(idOrProjectPath)reads a .NET user secrets store (~/.microsoft/usersecrets/<id>/secrets.json, or%APPDATA%\Microsoft\UserSecrets\<id>\secrets.jsonon Windows) on the host while the script is evaluated, without callingdotnet. Pass theUserSecretsId, or a.csproj(or a folder holding exactly one) to read it from. Nested JSON objects are flattened with:. A value is registered for redaction when the script reads it (indexer orTryGet), so read config throughSecretsonly if it is secret: a plain value such asRegionis not redacted unless it was read this way. Each line of a multi-line value (a PEM key) is also redacted on its own.Secrets.EnvFile(path, keys...)reads the named keys from a dotenv file. The values are registered for redaction. This call does not set them in the process environment or forward them to container commands; pass them to the operation that needs them. Use a separate file such as.env.secrets:.env.ando(or.env) is still loaded and forwarded to every container command by the normal env loading unless the run uses--no-env, and reading it here logs a warning that its keys are forwarded anyway. A file inside a git repository that is not gitignored fails at evaluation. A missing key fails at evaluation.
Both return a read-only set. Its indexer throws an error naming the missing key (never a value), and TryGet(key, out value) returns false instead.
var sp = Secrets.UserSecrets("simplesign365-dev");
var secret = sp["Deploy:Azure:ClientSecret"];
var cf = Secrets.EnvFile(".env.secrets", "CLOUDFLARE_API_TOKEN", "CLOUDFLARE_ACCOUNT_ID");
Cloudflare.UseCredentials(cf["CLOUDFLARE_API_TOKEN"], cf["CLOUDFLARE_ACCOUNT_ID"]);
BuildPath vs DirectoryRef
ANDO has two path types. Operations like Npm.Ci(), Cloudflare.PagesDeploy(), Playwright.Test(), and Ando.Build() require DirectoryRef, not BuildPath.
// Root returns BuildPath - use for path construction
var outputPath = Root / "dist";
Dotnet.Publish(app, o => o.Output(outputPath)); // OK: accepts string/BuildPath
// Directory() returns DirectoryRef - use for operations
var frontend = Directory("./frontend");
Npm.Ci(frontend); // OK: requires DirectoryRef
// WRONG: Npm.Ci(Root) - BuildPath is not DirectoryRef
// Use Directory(".") to reference the project root as DirectoryRef:
Npm.Ci(Directory(".")); // OK
Profiles
Profiles allow conditional execution of build steps. DefineProfile() takes a single argument (the name) and returns a Profile with implicit bool conversion. There is no HasProfile(), HasAnyProfile(), or Profile() function.
// Define profiles at the top of your build.csando
var release = DefineProfile("release");
var publish = DefineProfile("publish");
// Project references
var app = Dotnet.Project("./src/App/App.csproj");
var tests = Dotnet.Project("./tests/App.Tests/App.Tests.csproj");
// Always run build and tests
Dotnet.Build(app);
Dotnet.Test(tests);
// Only run when "release" profile is active
if (release) {
Dotnet.Publish(app, o => o.Output(Root / "dist"));
Git.Tag("v1.0.0");
}
// Only run when "publish" profile is active
if (publish) {
Nuget.EnsureAuthenticated();
Nuget.Pack(app);
Nuget.Push(app); // skips packages that already exist by default
}
// CLI usage:
// ando # Build and test only
// ando -p release # Build, test, publish, and tag
// ando -p publish # Build, test, pack, and push to NuGet
Log
Logging operations for outputting messages during the build. Visibility depends on verbosity level.
// Informational messages (visible at Normal verbosity)
Log.Info("Starting build process...");
// Warnings (visible at Minimal verbosity and above)
Log.Warning("Cache directory not found, rebuilding from scratch");
// Errors (always visible)
Log.Error("Build failed: missing dependency");
// Debug messages (only visible at Detailed verbosity)
Log.Debug($"Processing file: {filePath}");