Skip to content

Instantly share code, notes, and snippets.

Created January 28, 2016 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/e04333e0aa5173a3b090 to your computer and use it in GitHub Desktop.
Save anonymous/e04333e0aa5173a3b090 to your computer and use it in GitHub Desktop.
Build Target and Web.config file transformations
Target "Build" (fun _ ->
!! "ContractLookup.sln"
|> MSBuild buildDir "Build" [
"Optimize", "True"
"DebugSymbols", "True"
"Configuration", "Debug"
"Platform", "Any CPU"
]
|> Log "Build-Output: "
let fileMap = new WebConfigurationFileMap()
fileMap.VirtualDirectories.Add("/config", new VirtualDirectoryMapping(webConfigDestDir, true))
fileMap.VirtualDirectories.Add("/", new VirtualDirectoryMapping(webConfigDestDir, true, "web.config"))
!! (srcWebDir @@ "\web.*.config")
|> Seq.iter (fun file ->
let webConfig = (srcWebDir @@ "Web.Config")
let transformResult =
ExecProcess (fun info ->
{info with
FileName = (DeployScriptsDir @@ "/ctt.exe")
WorkingDirectory = buildDir
Arguments = sprintf "s:'%s' d:'%s/web.config.test' t:'%s' i e:utf8" webConfig webConfigDestDir file} (TimeSpan.FromMinutes 5.0))
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")
|> Log "Transform-Output: "
CopyDir (buildDir @@ "_PublishedWebsites/ContractLookup.Web") "ContractLookup" (fun f -> f.EndsWith ".config")
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment