buildf#-fakefsi

cannot specify Target when running FAKE with fsi --exec


I want to execute FAKE script with fsi --exec because it is so much faster than using FAKE.exe. However, I cannot understand how to specify a target.

This I can do:

FAKE.exe build.fsx Clean

This I want to do (but doesn't work, it will use the default target):

fsi --exec build.fsx Clean 

Any hints?

Thanks

Rasmus


Solution

  • You have to do a little extra work,

    At the start of your script setup or default a build param and at the end of your script use the default target construct, something like:

    #I "pathToYourFale\\FAKE\\tools"
    #r @"FakeLib.dll"
    
    
    open Fake
    open Fake.EnvironmentHelper
    
    // Process command args as Fake utilities don't work from fsi invoke
    for arg in fsi.CommandLineArgs do
         tracefn "arg: %s" arg
         if arg.StartsWith("target=") then target <- arg.Split('=').GetValue(1) :?> string
         else if arg.StartsWith("Target=") then target <- arg.Split('=').GetValue(1) :?> string
    
    ...
    Your script here
    ...
    ...
    
    AdditionalSyntax.RunParameterTargetOrDefault "target" "target"
    

    This should work for both Fake invokes and Fsi invokes e.g.

    fsi yourScript.fsx target="Yourtarget"
    

    The command arg handling is a bit clunky, anybody got a better suggestion on how to process?