Adrian Russell
Adrian Russell

Reputation: 4115

Sharing const variables across FAKE fsx scripts

Is there any way to share a variable by including a fsx script within another fsx script.

e.g script buildConsts.fsx contains

let buildDir = "./build/"

I want to reference this in other build scripts e.g.

#load @".\buildConsts.fsx"
let testDlls = !! (buildDir + "*Test*.dll")

When I attempt to run the script the 'buildDir' variable the script fails to compile.

This is a fairly common approach that is used with tools such as MSBuild and PSAKE to modularise scripts. Is this the correct approach with FAKE ?

Upvotes: 0

Views: 150

Answers (1)

Tomas Petricek
Tomas Petricek

Reputation: 243061

What you're doing should work - what exactly is the error message that you're getting?

I suspect that the problem is that F# automatically puts the contents of a file in a module and you need to open the module before you can access the constants. The module is named based on the file name, so in your case buildConsts.fsx will generate a module named BuildConsts. You should be able to use it as follows:

#load @".\buildConsts.fsx"
open BuildConsts

let testDlls = !! (buildDir + "*Test*.dll")

You can also add an explicit module declaration to buildconsts.fsx, which is probably a better idea as it is less fragile (won't change when you rename the file):

moule BuildConstants

let buildDir = "./build/"

Upvotes: 2

Related Questions