简体   繁体   English

在FAKE fsx脚本中共享const变量

[英]Sharing const variables across FAKE fsx scripts

Is there any way to share a variable by including a fsx script within another fsx script. 是否可以通过在另一个fsx脚本中包含一个fsx脚本来共享变量。

eg script buildConsts.fsx contains 例如脚本buildConsts.fsx包含

let buildDir = "./build/"

I want to reference this in other build scripts eg 我想在其他构建脚本中引用这个

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

When I attempt to run the script the 'buildDir' variable the script fails to compile. 当我尝试运行脚本“ buildDir”变量时,脚本无法编译。

This is a fairly common approach that is used with tools such as MSBuild and PSAKE to modularise scripts. 这是一种相当普遍的方法,与MSBuild和PSAKE等工具一起使用来对脚本进行模块化。 Is this the correct approach with FAKE ? 这是使用FAKE的正确方法吗?

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. 我怀疑问题在于F#自动将文件的内容放入模块中,您需要先打开模块,然后才能访问常量。 The module is named based on the file name, so in your case buildConsts.fsx will generate a module named BuildConsts . 该模块是根据文件名命名的,因此在您的情况下, buildConsts.fsx将生成一个名为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): 您还可以在buildconsts.fsx添加一个显式的模块声明,这可能是一个更好的主意,因为它不那么脆弱(重命名文件时不会更改):

moule BuildConstants

let buildDir = "./build/"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM