kuang
kuang

Reputation: 727

FAKE error when trying to use Fake.FscHelper

I'm trying to use FAKE to build my F# project. The build.fsx looks like below and works fine.

#r "packages/FAKE/tools/FakeLib.dll"

open Fake

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

RunTargetOrDefault "Default"

Then I want to use fsc from FAKE. Following the official tutorial, I added one line open Fake.FscHelper and get below error message:

#r "packages/FAKE/tools/FakeLib.dll"

open Fake
open Fake.FscHelper

// this value is not a function and can not be applied
// union case FscParam.Target: TargetType -> FscParam
Target "Default" (fun _ ->
~~~~~~~~~~~~~~~~
    trace "Hello World from FAKE"
)

RunTargetOrDefault "Default"

I appreciate if anyone can give me any advice.

I'm using VS Code on Mac with Mono 4.2.1.

And my paket.lock looks like below:

NUGET
  remote: https://www.nuget.org/api/v2
  specs:
    FAKE (4.21.0)
    FSharp.Core (4.0.0.1)
    FsUnit (2.0.0)
      FSharp.Core (>= 3.1.2.5)
      NUnit (3.0.1)
    NUnit (3.0.1)

Upvotes: 1

Views: 136

Answers (2)

cloudRoutine
cloudRoutine

Reputation: 370

Change the order of the open statements

#r @"packages/FAKE/tools/FakeLib.dll"
open Fake.FscHelper
open Fake

Target "a" (fun _ -> 
  ["a.fs"] |> Compile []

The order of your open statements determines the precedence of the name resolution with the later opened modules and namespaces taking precedent.

Upvotes: 2

Fyodor Soikin
Fyodor Soikin

Reputation: 80744

This happens because the module FscHelper defines a constructor called Target (see source), and that constructor conflicts with the Target function from the TargetHelper module. There is an issue filed about it.

Until the issue is fixed, there are three ways to work around this ambiguity:

  1. Don't open FscHelper, just use all its innards in a qualified manner (e.g. FscHelper.Compile etc.)

  2. Re-alias the TargetHelper.Target function in the local scope:

    open Fake
    open Fake.FscHelper
    
    let Target = TargetHelper.Target
    
    Target "Default" (fun _ ->
        trace "Hello World from FAKE"
    )
    
  3. Reorder the open statements:

    open Fake.FscHelper
    open Fake
    

And since you're using this helper, note that the documentation for it is outdated. In particular, the Fsc task is deprecated in favor of the Compile task (see source).

Upvotes: 4

Related Questions