Skip to content

Tasks | Inner functions

olegz edited this page Mar 16, 2026 · 4 revisions

Built-in functions

These functions are available inside recipe { ... } blocks. All require do! or let! syntax.

trace

Writes a message to the build log at the specified level.

do! trace Message "Build started"
do! trace Info "Compiling %s v%s" name version
do! trace Error "Failed: %s" errorMessage

Levels: Message, Error, Command, Warning, Info, Debug, Verbose, Never.

need

Demands targets to be built. Pauses execution until all are ready. Records dependencies.

do! need ["lib.dll"; "utils.dll"]

needFiles

Same as need but accepts a Filelist instead of strings.

let! files = getFiles !! "src/**/*.fs"
do! needFiles files

needSequentially

Demands targets one at a time, waiting for each to complete before starting the next.

do! needSequentially ["build"; "test"; "deploy"]

getFiles

Evaluates a fileset to a file list and records a dependency on the result. The target reruns when files are added or removed.

let! files = getFiles <| fileset {
    basedir "src"
    includes "**/*.fs"
}

dependsOn

Combines getFiles and needFiles — evaluates the fileset and demands all matching files.

do! dependsOn !! "src/**/*.fs"

getTargetFile, getTargetFullName

Get the current target's file. Only works for file rules.

let! file = getTargetFile()        // File
let! fullPath = getTargetFullName() // string

getTargetFiles

Get all target files for multi-file rules.

let! [exeFile; xmlFile] = getTargetFiles()

getRuleMatch, getRuleMatches

Extract named capture groups from the rule pattern.

"(dir:*)/(file:*).fs" ..> recipe {
    let! dir = getRuleMatch "dir"
    let! file = getRuleMatch "file"
    let! allMatches = getRuleMatches()  // Map<string,string>
}

getVar

Gets a script variable value and records a dependency.

let! version = getVar "VERSION"  // string option

For new code, prefer typed variables over getVar.

getEnv

Gets an environment variable value and records a dependency.

let! user = getEnv "USERNAME"  // string option

For new code, prefer typed variables with Var.env.

getCtxOptions

Gets the script execution options.

let! opts = getCtxOptions()
let root = opts.ProjectRoot

alwaysRerun

Forces the target to rebuild regardless of dependencies.

do! alwaysRerun()

Clone this wiki locally