简体   繁体   English

在FAKE中发布网站(F#Make)

[英]Publish website in FAKE (F# Make)

是否可以发布网站而不是将其构建为FAKE脚本的一部分?

I do not have experience with this myself, but it looks like there are two ways to run the web deploymnent process by hand. 我自己没有这方面的经验,但看起来有两种方法可以手动运行web deploymnent流程。 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 ). 一个(看起来较旧)是使用特殊目标(如此处所述 )调用MSBuild,另一个选项(看起来更现代)是使用MSDeploy工具( 具有命令行界面 )。

Both of these should be easy to call from FAKE script. 这些都应该很容易从FAKE脚本调用。 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: 调用MSBuild脚本应该如下所示:

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! 正如我所说,我没有对此进行测试(因此可能完全错误),但希望它可以指向一个有用的方向,在一些Web部署或FAKE专家来之前!

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: 以下是build.fsx的一段代码,说明了这种方法:

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 . 使用此代码,当运行其中一个目标“Test”,“AcceptanceTest”,“Deploy”时,将根据LocalTestServer.pubxml定义的发布配置文件发布网站。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM