Skip to content

Instantly share code, notes, and snippets.

@JaykeOps
Created May 26, 2018 09:55
Show Gist options
  • Save JaykeOps/0a6dd53ccc12b81f71a3609b725015ac to your computer and use it in GitHub Desktop.
Save JaykeOps/0a6dd53ccc12b81f71a3609b725015ac to your computer and use it in GitHub Desktop.
FS Build.fsx
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------
#r "./packages/build/FAKE/tools/FakeLib.dll"
open Fake
open System
// --------------------------------------------------------------------------------------
// Build variables
// --------------------------------------------------------------------------------------
let buildDir = "./build/"
let appReferences = !! "/**/*.fsproj"
let dotnetcliVersion = "2.0.2"
let mutable dotnetExePath = "dotnet"
// --------------------------------------------------------------------------------------
// Helpers
// --------------------------------------------------------------------------------------
let run' timeout cmd args dir =
if execProcess (fun info ->
info.FileName <- cmd
if not (String.IsNullOrWhiteSpace dir) then
info.WorkingDirectory <- dir
info.Arguments <- args
) timeout |> not then
failwithf "Error while running '%s' with args: %s" cmd args
let run = run' System.TimeSpan.MaxValue
let runDotnet workingDir args =
let result =
ExecProcess (fun info ->
info.FileName <- dotnetExePath
info.WorkingDirectory <- workingDir
info.Arguments <- args) TimeSpan.MaxValue
if result <> 0 then failwithf "dotnet %s failed" args
// --------------------------------------------------------------------------------------
// Targets
// --------------------------------------------------------------------------------------
Target "Clean" (fun _ ->
CleanDirs [buildDir]
)
Target "InstallDotNetCLI" (fun _ ->
dotnetExePath <- DotNetCli.InstallDotNetSDK dotnetcliVersion
)
Target "Restore" (fun _ ->
appReferences
|> Seq.iter (fun p ->
let dir = System.IO.Path.GetDirectoryName p
runDotnet dir "restore"
)
)
Target "Build" (fun _ ->
appReferences
|> Seq.iter (fun p ->
let dir = System.IO.Path.GetDirectoryName p
runDotnet dir "build"
)
)
// --------------------------------------------------------------------------------------
// Build order
// --------------------------------------------------------------------------------------
"Clean"
==> "InstallDotNetCLI"
==> "Restore"
==> "Build"
RunTargetOrDefault "Build"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment