Skip to content

Instantly share code, notes, and snippets.

@catlion
Last active January 28, 2016 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save catlion/a2e030510f64d300ecd7 to your computer and use it in GitHub Desktop.
Save catlion/a2e030510f64d300ecd7 to your computer and use it in GitHub Desktop.
Build.fsx target fragment
#r "c:/dev/git/ContractLookup/tools/FAKE/tools/FakeLib.dll"
#r "System.Configuration.dll"
open Fake
open Fake.AssemblyInfoFile
open Fake.ReleaseNotesHelper
open Fake.ProcessHelper
open System
open System.Configuration
open System.IO
open System.Web.Configuration
let srcWebDir = "./ContractLookup/ContractLookup.Web"
let buildDir = "./build"
let releaseDir = "./release"
let deployScriptsDir = "./DeployScripts"
let webConfigDestDir = (buildDir @@ "config")
let transformWebConfig(file: string) =
let fileMap = WebConfigurationFileMap()
fileMap.VirtualDirectories.Add("/config", VirtualDirectoryMapping(webConfigDestDir, true))
fileMap.VirtualDirectories.Add("/", VirtualDirectoryMapping(webConfigDestDir, true, "web.config"))
let webConfig = srcWebDir @@ "Web.Config"
let timeout = TimeSpan.FromMinutes 5.0
let transformResult =
ExecProcess (fun info ->
info.FileName <- deployScriptsDir @@ "/ctt.exe"
info.WorkingDirectory <- buildDir
info.Arguments <- sprintf "s:'%s' d:'%s/web.config.test' t:'%s' i e:utf8" webConfig webConfigDestDir file) timeout
if transformResult <> 0 then failwithf "Config file could not be transformed"
try
WebConfigurationManager.OpenWebConfiguration(fileMap, destConfig)
with
| :? System.Exception -> failwithf "Config file could not be validated"
Target "Clean" (fun _ ->
CleanDirs [buildDir;releaseDir]
)
Target "Version" (fun _ ->
let release = LoadReleaseNotes "RELEASE_NOTES.md"
let tfsBuildNumber = Environment.GetEnvironmentVariable "BUILD_BUILDNUMBER"
trace tfsBuildNumber
let version = (release.AssemblyVersion + "." + tfsBuildNumber)
trace version
let common = [
Attribute.Version version
Attribute.FileVersion version
]
common
|> CreateCSharpAssemblyInfo "./SolutionInfo.cs"
)
Target "Build" (fun _ ->
!! "ContractLookup.sln"
|> MSBuild buildDir "Build" [
"Optimize", "True"
"DebugSymbols", "True"
"Configuration", "Debug"
"Platform", "Any CPU"
]
|> Log "Build-Output: "
!! (srcWebDir @@ "\web.*.config")
|> Seq.iter transformWebConfig
CopyDir (buildDir @@ "_PublishedWebsites/ContractLookup.Web") "ContractLookup" (fun f -> f.EndsWith ".config")
)
Target "UnitTests" (fun _ ->
!! (buildDir @@ @"\*.Specs.dll")
|> NUnit (fun p ->
{p with
ErrorLevel = Error
TimeOut = TimeSpan.FromSeconds(15.0)
DisableShadowCopy = true
OutputFile = buildDir + "TestResults.xml"})
)
Target "Package" (fun _ ->
CopyDir releaseDir (buildDir @@ "_PublishedWebsites") allFiles
CopyDir (releaseDir @@ "DeployScripts") ("DeployScripts") allFiles
)
"Build" <== ["Clean";"Version"]
"UnitTests" <== ["Build"]
"Package" <== ["UnitTests"]
RunTargetOrDefault "Package"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment