Search code examples
f#tokentype-safetyf#-fake

How do you use tokens instead of strings for targets?


I found that you can use tokens instead of strings for target names in FAKE scripts. Could you translate my sample script into one that uses provided operators?

// include Fake lib
#r "packages/FAKE/tools/FakeLib.dll" open Fake

// Targets 
Target "Clean" (fun _ ->
    CleanDir "./build/")

Target "Default" (fun _ ->
    trace "Hello World from FAKE" )

// Dependencies 
"Clean"   ==> "Default"

// start build 
RunTargetOrDefault "Default"

Solution

  • You can do this with the following.

    open Fake
    
    // Targets 
    Target?Clean (fun _ ->
        CleanDir "./build/")
    
    Target?Default (fun _ ->
        trace "Hello World from FAKE" )
    
    // Dependencies 
    "Clean"   ==> "Default"
    
    // start build 
    RunTargetOrDefault?Default
    

    For reference it might be worth having a look at other uses dynamic operator for F# here. So you get a better feel for what it is doing.