Skip to content

Instantly share code, notes, and snippets.

@fwaris

fwaris/build.fsx Secret

Last active Nov 2, 2018
Embed
What would you like to do?
Sample FAKE script that builds and F# app and packages is for ClickOnce deployment
// include Fake lib
#r @"tools\FAKE\tools\FakeLib.dll"
#r "System.Xml.Linq"
open Fake
let version = "1.0.0.1"
let appName = "MyApp"
let publisher = sprintf "%A" "Publisher Name"
let cert = @".\MyApp\Cert.pfx"
let buildRoot = @".\build"
let buildDir = sprintf @"%s\%s_%s" buildRoot appName (version.Replace('.','_'))
let buildDirSlash = buildDir + @"\"
let mage = sprintf "%A" @"C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\mage.exe"
let appManifest = sprintf @"%s/%s.exe.manifest" buildDir appName
let depManifest = sprintf @"%s/%s.application" buildRoot appName
let timeout = System.TimeSpan.FromSeconds(15.)
// Targets
Target "Clean" (fun _ -> CleanDir buildDir)
Target "BuildApp" (fun _ ->
!! @"MyApp/MyApp.fsproj"
|> MSBuildRelease buildDir "Build"
|> Log "AppBuild-Output: ")
Target "Prune" (fun _ ->
!+ (buildDirSlash + "*.pdb")
++ (buildDirSlash + "*.xml")
|> Scan
|> DeleteFiles
)
Target "AddDeployExt" (fun _ ->
!+ (buildDirSlash + @"\**\*.dll")
++ (buildDirSlash + @"\**\*.exe")
++ (buildDirSlash + @"\**\*.config")
++ (buildDirSlash + @"\**\*.csv")
++ (buildDirSlash + @"\**\*.dbml")
|> Scan
|> Seq.iter (fun f -> f |> Rename (f + ".deploy"))
)
Target "CreateAppManifest" (fun _ ->
let args =
sprintf
" -New Application -ToFile \"%s\" -Name %s -Version \"%s\" -Processor x86 -FromDirectory %s"
appManifest
appName
version
buildDir
ExecProcess (fun pi ->
pi.FileName <- mage
pi.Arguments <- args
)
timeout
|> ignore
)
Target "SignAppManifest" (fun _ ->
let args =
sprintf
" -Sign %s -CertFile %s -Password ***"
appManifest
cert
ExecProcess(fun pi ->
pi.FileName <- mage
pi.Arguments <- args
)
timeout
|> ignore
)
Target "CreateDeploymentManifest" (fun _ ->
let args =
sprintf
" -New Deployment -Version \"%s\" -Processor x86 -Install true -Publisher %s -AppManifest %s -ToFile %s"
version
publisher
appManifest
depManifest
ExecProcess(fun pi ->
pi.FileName <- mage
pi.Arguments <- args
)
timeout
|> ignore
)
Target "UpdateDeploymentManifest" (fun _ ->
let doc = System.Xml.Linq.XDocument.Load(depManifest)
let depNode = doc.Root.Elements() |> Seq.tryPick (fun e -> if e.Name.LocalName="deployment" then Some e else None)
let trustAttr = System.Xml.Linq.XName.Get("trustURLParameters","")
let depExtAttr = System.Xml.Linq.XName.Get("mapFileExtensions","")
depNode.Value.SetAttributeValue(trustAttr,"true")
depNode.Value.SetAttributeValue(depExtAttr,"true")
doc.Save(depManifest)
)
Target "SignDeploymentManifest" (fun _ ->
let args =
sprintf
" -Sign %s -CertFile %s -Password pdo"
depManifest
cert
ExecProcess(fun pi ->
pi.FileName <- mage
pi.Arguments <- args
)
timeout
|> ignore
)
// Default target
Target "Default" (fun _ ->
trace "packaged MyApp"
)
// Dependencies
"Clean"
==> "BuildApp"
==> "Prune"
==> "CreateAppManifest"
==> "SignAppManifest"
==> "AddDeployExt"
==> "CreateDeploymentManifest"
==> "UpdateDeploymentManifest"
==> "SignDeploymentManifest"
==> "Default"
// start build
Run "Default"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.