Can I pass a parameter to a F# FAKE build script?

Something like this should work.

From the command-line:

"..\packages\Fake.3.7.5\tools\Fake.exe" "build.fsx" dir=my/custom/dir/

In the build.fsx script:

let buildDir = getBuildParamOrDefault "dir" "./build/"

That will look for the dir parameter being passed in, and use it if it's assigned, otherwise it will default to ./build/


Non of the above fully worked for me. Below an adjusted solution.
The console command needs to be run with the -e flag:

"..\fake.exe" "build.fsx" -e dir=sample/directory

The build script is using Environment.environVarOrDefault "dir" "default\directory":

let buildDir = Environment.environVarOrDefault "dir" "default\directory"

Environment.environVar can also be used if no alternative is provided.

Finally the build script has to run with Target.runOrDefaultWithArguments. It will fail if it's executed with Target.runOrDefault:

// start build
Target.runOrDefaultWithArguments "DefaultBuildTarget"

Tags:

F#

F# Fake