如何参数化和重复构建步骤
How do I parameterise and repeat a build step
我正在编写一个 FAKE 脚本,它基本上会执行以下操作:-
1. Clean build outputs
2. Modify a configuration file with a specific value.
3. Perform a build.
4. Upload the outputs somewhere.
我已经写下了所有的个人任务。我现在需要做的是设置一组 FAKE 构建步骤以基本上重复上述步骤,每个配置值一次,例如假设配置文件有一个属性 "colour"。我想重复上述四个构建步骤,并在步骤 2 中使用其中一个值 [ "black"; "blue"; "red"; "white" ]
.
实现此目标的最佳方法是什么?我是否应该只做一个大型构建任务来完成所有这些任务,例如for 循环(似乎是错误的)?或者创建多个构建步骤,例如"Set Config to Blue" 和 "Set Config to Red" 等并为每种颜色重复整个构建流程(同样,似乎是错误的)?
你可以使用各种配置吗?例如:
BlueBuild:
[configsection]
[Color]Blue[/Color]
[/configsection]
RedBuild:
[configsection]
[Color]Red[/Color]
[/configsection]
查看以下文章:
How to select different app.config for several build configurations
http://www.hanselman.com/blog/managingmultipleconfigurationfileenvironmentswithprebuildevents.aspx
你可以这样做
#r "tools/FAKE/tools/FakeLib.dll"
open Fake
Target "Clean" (fun _ ->
trace "Cleaning stuff..."
)
let config color = ignore()
Target "ConfigBlack" (fun _ ->
config "black"
)
Target "ConfigRed" (fun _ ->
config "red"
)
Target "Build" (fun _ ->
trace "Build solution"
)
Target "Upload" (fun _ ->
trace "Upload artifacts"
)
"Clean"
=?> ("ConfigBlack",hasBuildParam "black")
=?> ("ConfigRed",hasBuildParam "red")
==> "Build"
==> "Upload"
Run "Upload"
之后你就可以像这样build Upload black
或build Upload red
打电话了
下面的脚本有效,但使用了 ExecutedTargets
,我认为你不应该使用它。
#I "tools/FAKE/tools"
#r "FakeLib.dll"
open Fake
let mutable value = "Foo"
Target "Clean" (fun _ ->
trace "clean target"
)
Target "Modify config file" (fun _ ->
trace (sprintf "===========> Modify config file: '%s'" value)
)
Target "Perform build" (fun _ ->
trace "Perform build"
)
Target "Default" (fun _ -> ())
"Clean"
==> "Modify config file"
==> "Perform build"
==> "Default"
["black"; "blue"; "red"; "white"]
|> List.iter(fun v ->
value <- v
Run <| getBuildParamOrDefault "target" "Default"
ExecutedTargets.Clear()
)
文档不是很好,但您可以通过 TargetTemplateWithDependecies
以编程方式创建目标
我会添加一些文档。
我这样做的方法基本上是编写一个生成目标的辅助函数——就像模板依赖一样——但也会生成 "common" 目标的多个实例;每个都根据变量元素的名称而有所不同,例如
let targets =
[ "Blue: Clean"
"Blue: Modify Config"
"Blue: Perform Build"
"Blue: Upload outputs"
"Red: Clean"
"Red: Modify Config"
"Red: Perform Build"
"Red: Upload outputs"
"Yellow: Clean"
"Yellow: Modify Config"
"Yellow: Perform Build"
"Yellow: Upload outputs" ]
然后您可以轻松地将 then 构建到顺序依赖链中,例如
targets |> List.reduce (==>)
虽然这不是我所希望的,但它对我来说效果很好,让我看穿了假货。
我正在编写一个 FAKE 脚本,它基本上会执行以下操作:-
1. Clean build outputs
2. Modify a configuration file with a specific value.
3. Perform a build.
4. Upload the outputs somewhere.
我已经写下了所有的个人任务。我现在需要做的是设置一组 FAKE 构建步骤以基本上重复上述步骤,每个配置值一次,例如假设配置文件有一个属性 "colour"。我想重复上述四个构建步骤,并在步骤 2 中使用其中一个值 [ "black"; "blue"; "red"; "white" ]
.
实现此目标的最佳方法是什么?我是否应该只做一个大型构建任务来完成所有这些任务,例如for 循环(似乎是错误的)?或者创建多个构建步骤,例如"Set Config to Blue" 和 "Set Config to Red" 等并为每种颜色重复整个构建流程(同样,似乎是错误的)?
你可以使用各种配置吗?例如:
BlueBuild:
[configsection]
[Color]Blue[/Color]
[/configsection]
RedBuild:
[configsection]
[Color]Red[/Color]
[/configsection]
查看以下文章: How to select different app.config for several build configurations
http://www.hanselman.com/blog/managingmultipleconfigurationfileenvironmentswithprebuildevents.aspx
你可以这样做
#r "tools/FAKE/tools/FakeLib.dll"
open Fake
Target "Clean" (fun _ ->
trace "Cleaning stuff..."
)
let config color = ignore()
Target "ConfigBlack" (fun _ ->
config "black"
)
Target "ConfigRed" (fun _ ->
config "red"
)
Target "Build" (fun _ ->
trace "Build solution"
)
Target "Upload" (fun _ ->
trace "Upload artifacts"
)
"Clean"
=?> ("ConfigBlack",hasBuildParam "black")
=?> ("ConfigRed",hasBuildParam "red")
==> "Build"
==> "Upload"
Run "Upload"
之后你就可以像这样build Upload black
或build Upload red
下面的脚本有效,但使用了 ExecutedTargets
,我认为你不应该使用它。
#I "tools/FAKE/tools"
#r "FakeLib.dll"
open Fake
let mutable value = "Foo"
Target "Clean" (fun _ ->
trace "clean target"
)
Target "Modify config file" (fun _ ->
trace (sprintf "===========> Modify config file: '%s'" value)
)
Target "Perform build" (fun _ ->
trace "Perform build"
)
Target "Default" (fun _ -> ())
"Clean"
==> "Modify config file"
==> "Perform build"
==> "Default"
["black"; "blue"; "red"; "white"]
|> List.iter(fun v ->
value <- v
Run <| getBuildParamOrDefault "target" "Default"
ExecutedTargets.Clear()
)
文档不是很好,但您可以通过 TargetTemplateWithDependecies
以编程方式创建目标我会添加一些文档。
我这样做的方法基本上是编写一个生成目标的辅助函数——就像模板依赖一样——但也会生成 "common" 目标的多个实例;每个都根据变量元素的名称而有所不同,例如
let targets =
[ "Blue: Clean"
"Blue: Modify Config"
"Blue: Perform Build"
"Blue: Upload outputs"
"Red: Clean"
"Red: Modify Config"
"Red: Perform Build"
"Red: Upload outputs"
"Yellow: Clean"
"Yellow: Modify Config"
"Yellow: Perform Build"
"Yellow: Upload outputs" ]
然后您可以轻松地将 then 构建到顺序依赖链中,例如
targets |> List.reduce (==>)
虽然这不是我所希望的,但它对我来说效果很好,让我看穿了假货。