利用FlubuCore用C#来写DevOps脚本的方法详解

2020-07-06 11:00:41王旭
_Build/BuildScript/BuildScript.cs 的这段代码里面的 compile,你可以随意更改,只需要和命令保持一致。

protected override void ConfigureTargets(ITaskContext context)
{
 var compile = context.CreateTarget("compile")
  .SetDescription("Compiles the solution.")
  .AddCoreTask(x => x.Build());
}

后面基本上你需要的构建的所有的东西都可以写到 ConfigureTargets 里面了。

最后的输出:

D:FlubuTest>flubu compile
Flubu v.4.3.5.0
Build script file name was not explicitly specified, searching the default locations:
Found it, using the build script file 'BuildScript/BuildScript.cs'.
Executing target compile
Executing task DotnetBuildTask
   Running program 'C:Program Filesdotnetdotnet.exe':(work.dir='',args=' build FlubuTest.sln')
   用于 .NET Core 的 Microsoft (R) 生成引擎版本 16.6.0+5ff7b0c9e
   版权所有(C) Microsoft Corporation。保留所有权利。
     正在确定要还原的项目…
     所有项目均是最新的,无法还原。
     BuildScript -> D:FlubuTestBuildScriptbinDebugnetcoreapp2.1BuildScript.dll
     mywebapp -> D:FlubuTestsrcmywebappbinDebugnetcoreapp3.1mywebapp.dll
     mywebapp -> D:FlubuTestsrcmywebappbinDebugnetcoreapp3.1mywebapp.Views.dll
   已成功生成。
       0 个警告
       0 个错误
   已用时间 00:00:02.51
compile finished (took 3 seconds)

BUILD SUCCESSFUL
Build finish time: 2020/7/4 0:47
Build duration: 00:00:03 (3 seconds)

可能有人会问,这和我用 dotnet build FlubuTest.sln 有区别吗?
针对这个示例而言,是没区别,但是你可以自己扩展啊,扩展后不就有区别了。比如你想build之前先清理文件夹之类的,可以这么写。

 var compile = context.CreateTarget("compile")
    .SetDescription("Compiles the solution.")
    .AddCoreTask(x => x.Clean())
    .AddCoreTask(x => x.Build());

借助于 flubu 提供的能力,可以在 CI/CD 界面解决很多复杂的构建问题。

总结

上面的仅仅是一个入门,如果你觉得你们项目刚好需要那么你可以去官方的文档去查看,里面有更加详细的使用指南,当然也可以在这个博客下面留言或者去GitHub提交issue询问。

GitHub: https://github.com/dotnetcore/FlubuCore

FlubuCore 给我们提供了一种可以快速编写 DevOps 脚本的能力,利用这种能力可以让DevOps变得更加简单和高效,从而提高效率节约时间。

到此这篇关于利用FlubuCore用C#来写DevOps脚本的方法详解的文章就介绍到这了,更多相关C# DevOps脚本内容请搜索易采站长站以前的文章或继续浏览下面的相关文章希望大家以后多多支持易采站长站!