-->

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

2019-04-03 05:58发布

问题:

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?

回答1:

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/



回答2:

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



标签: f# f#-fake