Reputation: 2333
I'm just getting started with FAKE. I really like the idea. In the tutorials the set the build and deploy directories.
// Directories
let buildDir = "./build/"
let testDir = "./test/"
let deployDir = "./deploy/"
and then later reference those which is fine, but is it possible to pass that as a parameter? Maybe to as Task where I can use it later?
Upvotes: 27
Views: 5718
Reputation: 8782
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"
Upvotes: 2
Reputation: 2205
This answer accepted doesn't seem to work for FAKE 5.
You will want to set the environment variable before running the script.
dir=my/custom/dir/ ./fake.sh run build.fsx
As linked in the comments above.
http://www.github.com/fsharp/FAKE/issues/2125#issuecomment-427684505
Upvotes: 0
Reputation: 1083
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/
Upvotes: 42