如何告诉FAKE使用.fs
编译fsc
文件?
奖励积分,用于解释如何传递-a
和-target:dll
等参数。
编辑:我应该澄清一下,我试图在没有的情况下使用MSBuild / xbuild / .sln
文件。换句话说,我希望FAKE完全取代MSBuild / xbuild。
答案 0 :(得分:3)
FAKE有直接调用F#编译器的任务。通常,您可以使用Fsc
任务。如果您希望目标将F#源文件MyFile.fs
编译为MyFile.exe
,您可以执行以下操作:
Target "MyFile.exe" (fun _ ->
["MyFile.fs"]
|> Fsc (fun ps -> ps))
Fsc
任务允许您编译多个源文件并指定每个F#编译参数。这个简单的例子不能做到这一点,但你可以做到。要阅读详细信息,请转到the tutorial。
答案 1 :(得分:1)
我建议您阅读关于此主题的FAKE制作的Ian Battersby's page
代码摘录:
第一
#!/bin/bash
TARGET=$1
BUILDTARGETS=$2
if [ -z "$BUILDTARGETS" ]
then
BUILDTARGETS="/Library/Frameworks/Mono.framework/Libraries/mono/xbuild/Microsoft/VisualStudio/v9.0"
fi
if [ -z "$TARGET" ]
then
CTARGET="Default"
else
CTARGET=`echo ${TARGET:0:1} | tr "[:lower:]" "[:upper:]"``echo ${TARGET:1} | tr "[:upper:]" "[:lower:]"`
fi
if [ ! -d "$BUILDTARGETS" ]
then
echo "BuildTargets directory '${BUILDTARGETS}' does not exist."
exit $?
else
export BUILDTARGETS="$BUILDTARGETS"
fi
echo "Executing command: $CTARGET"
mono packages/FAKE.1.64.6/tools/Fake.exe build.fsx target=$CTARGET
然后
#I @"packages/FAKE.1.64.6/tools"
#r "FakeLib.dll"
open Fake
let buildDir = @"./build/"
let testDir = @"./test"
let fxReferences = !! @"*/*.csproj"
let testReferences = !! @"Tests/**/*.csproj"
let buildTargets = environVarOrDefault "BUILDTARGETS" ""
Target "Clean" (fun _ ->
CleanDirs [buildDir; testDir]
)
Target "Build" (fun _ ->
MSBuild buildDir "Build" ["Configuration","Debug"; "VSToolsPath",buildTargets] fxReferences
|> Log "Build-Output: "
)
Target "BuildTest" (fun _ ->
MSBuildRelease testDir "Build" testReferences
|> Log "Test-Output: "
)
Target "Test" (fun _ ->
!! (testDir + @"/*.Tests.dll")
|> xUnit (fun p ->
{ p with
ShadowCopy = true;
HtmlOutput = true;
XmlOutput = true;
OutputDir = testDir })
)
"Clean"
==> "Build"
"Build"
==> "BuildTest"
Target "Default" DoNothing
RunParameterTargetOrDefault "target" "Default"
答案 2 :(得分:1)
这是一个可能有用的 - 尽管在Yawar上面的回答中确实很小的扭曲,这可能使它与你可能遇到的其他FAKE例子更好一点。
Fsc
帮助函数想要一个文件名的字符串列表,这样就可以了。但大多数示例使用!!
运算符来查找文件,这会导致FileIncludes
不是字符串列表。您可以将FileIncludes
转换为适合Fsc
Seq.toList
的字符串列表。
为了彻底,我还将事物转换为相对路径名(可能只是个人怪癖)。
所以这是一个搜索所有*.fs
文件并使用一些有代表性的编译器选项编译它们的例子:
Target "BuildApp" (fun _ -> // Compile application source code
!! (srcApp @@ @"**/*.fs") // Look for F# source files
|> Seq.map toRelativePath // Pathnames relative to current directory
|> Seq.toList // Convert FileIncludes to string list
|> Fsc (fun p -> // which is what the Fsc task wants
{p with // Fsc parameters: making an executable,
FscTarget = Exe // for any CPU, directing output to build
Platform = AnyCpu // area (both assembly & XML doc).
Output = ...exe file... // Executable generated
OtherParams = ["--doc:" + ...xmldoc file...) ]})
) //
正如Yawar指出的那样,the tutorial中涵盖了大量其他编译器选项。