Is is possible to publish a website instead of building it as part of a FAKE script?
-
I don't think there is a built-in task for doing that, but you can certainly do that (just like anything else you can program in F#). How do you want to publish the site? Using FTP or something else? – Tomas Petricek May 10 '13 at 00:36
-
Hi Tomas, sorry specifically I mean 'publish' in the Visual Studio sense rather than a generic publish it somewhere. Is that also what you meant? If so, then it need only publish it to disk, but it runs the web.config transforms, removes unnecessary files etc – mattcole May 10 '13 at 02:11
-
I see, yes that makes sense. I looked around on the internet and posted some ideas in an answer. – Tomas Petricek May 10 '13 at 03:24
2 Answers
I do not have experience with this myself, but it looks like there are two ways to run the web deploymnent process by hand. One (looks older) is to invoke MSBuild with a special target (as described here) and another option (looks more modern) is to use the MSDeploy tool (which has a command line interface).
Both of these should be easy to call from FAKE script. Here is a sample that calls a command line tool:
Target "Deploy" (fun _ ->
let result =
ExecProcess (fun info ->
info.FileName <- "file-to-run.exe"
info.Arguments <- "--parameters:go-here"
) (System.TimeSpan.FromMinutes 1.0)
if result <> 0 then failwith "Operation failed or timed out"
)
Calling an MSBuild script should look something like this:
Target "BuildTest" (fun _ ->
"Blah.csproj"
|> MSBuildRelease "" "ResolveReferences;_CopyWebApplication"
|> ignore
)
As I said, I have not tested this (so it might be completely wrong), but hopefully it can point you into a useful direction, before some web deployment or FAKE experts come to SO!

- 1
- 1

- 240,744
- 19
- 378
- 553
Here is one way to do it. (Actually it doesn't exactly answer the question, because publishing is not performed without building.)
- Decide which targets need to publish the website.
- Make them depend on the "Build" target.
- Make the "Build" target publish the site using a publish profile in case publishing is needed.
Here is a piece of code from build.fsx
illustrating this approach:
let testProjects = @"src/**/*Tests.csproj"
let requestedTarget = getBuildParamOrDefault "target" ""
let shouldDeploy =
match requestedTarget with
| "Test" | "AcceptanceTest" | "Deploy" -> true
| _ -> false
// *** Define Targets ***
Target "BuildApp" (fun _ ->
let properties =
if shouldDeploy
then [ ("DeployOnBuild", "true"); ("PublishProfile","LocalTestServer.pubxml") ]
else []
!! @"src/**/*.csproj"
-- testProjects
|> MSBuildReleaseExt null properties "Build"
|> Log "Build-Output: "
)
// Other targets and dependencies omitted.
With this code in place, when one of the targets
"Test", "AcceptanceTest", "Deploy" is run, the website
gets published according to the publish profile defined in LocalTestServer.pubxml
.

- 6,371
- 3
- 44
- 56