跳转至

FlubuCore

Windows Build Travis NuGet Badge Gitter Twitter Member project of .NET Core Community License

概述

“FlubuCore - Fluent Builder Core”,跨平台的构建与部署自动化系统,通过直观的 Fluent 接口,使用 C# 定义构建和部署脚本。这使你的代码获得自动完成、IntelliSense、调试、FlubuCore 自定义分析器,以及在脚本中对整个 .NET 生态的原生性访问。

FlubuCore in action

通过 roslyn 的强大赋能,FlubuCore 提供有 .NET/.NET Core 控制台应用程序用于编译和执行脚本。以上示例均可从控制台运行:

  • FlubuCore runner flubu.exe Default
  • FlubuCore dotnet cli tool dotnet flubu Default
  • FlubuCore global tool flubu Default

功能与优势

  • 直观,易学。C#、流畅的 API 设计和 IntelliSense,使复杂脚本的构建变得举重若轻。
1
2
3
4
5
context.CreateTarget("Example")
  .DependsOn(fetchBuildVersionTarget)
  .AddTask(x => x.CompileSolutionTask())
  .AddTask(x => x.PublishNuGetPackageTask("packageId", "pathToNuspec"))
      .When(c => c.BuildSystems().Jenkins().IsRunningOnJenkins);
  • 内置大量常用任务,如运行测试、管理 ISS、创建部署包(deployment packages)、发布 NuGet 包、docker 任务、执行 PowerShell 脚本等。
1
2
3
4
5
6
7
8
context.CreateTarget("build")
   .AddTask(x => x.GitVersionTask())
   .AddTask(x => x.CompileSolutionTask("MySolution.sln").BuildConfiguration("Release");

context.CreateTarget("run.tests")
   .AddTask(x => x.XunitTaskByProjectName("MyProject").StopOnFail())
   .AddTask(x => x.NUnitTask(NunitCmdOptions.V3, "MyProject2").ExcludeCategory("Linux"))
   .AddCoreTask(x => x.CoverletTask("MyProject.dll"));
1
2
3
4
context.CreateTarget("MyCustomBuildTarget")
     .AddTask(x => x.CompileSolutionTask())
     .Do(MyCustomMethod)
     .Do(NuGetPackageReferencingExample);
  • 当脚本与项目文件一起使用时会自动加载程序集引用和 NuGet 包。当脚本单独执行(譬如在生产环境中使用 FlubuCore 脚本进行部署)时,可在特性(attributes)中添加引用(references)。
1
2
3
4
5
6
7
8
9
[NugetPackage("Newtonsoft.json", "11.0.2")]
[Assembly(".\Lib\EntityFramework.dll")]
public class BuildScript : DefaultBuildScript
{
   public void NuGetPackageReferencingExample(ITaskContext context)
    {
        JsonConvert.SerializeObject("Example");
    }
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
 public class SimpleScript : DefaultBuildScript
 {
    protected override void ConfigureTargets(ITaskContext context)
    {
        context.CreateTarget("Run.Libz")
        .AddTask(x => x.RunProgramTask(@"packages\LibZ.Tool\1.2.0\tools\libz.exe")
            .WorkingFolder(@".\src")
            .WithArguments("add")
            .WithArguments("--libz", "Assemblies.libz"));
    }
 }
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
 public class SimpleScript : DefaultBuildScript
 {
    [FromArg("sn", "If true app is deployed on second node. Otherwise not.")]
    public bool deployOnSecondNode { get; set; }


     protected override void ConfigureTargets(ITaskContext context)
     {
         context.CreateTarget("compile")
            .AddTask(x => x.CompileSolutionTask()
                .ForMember(y => y.SolutionFileName("someSolution.sln"), "solution", "The solution to build."));
     }
 }
1
  flubu.exe compile -solution=someOtherSolution.sln -sn=true
1
2
3
4
5
6
7
8
    public class ExampleFlubuPluginTask : TaskBase<int, ExampleFlubuPluginTask>
    {
        protected override int DoExecute(ITaskContextInternal context)
        {
            // Write your task logic here.
            return 0;
        }
    }
1
2
3
4
    context.CreateTarget("Run.Tests")
        .AddTaskAsync(x => x.NUnitTaskForNunitV3("TestProjectName1"))
        .AddTaskAsync(x => x.NUnitTaskForNunitV3("TestProjectName1"))
        .AddTaskAsync(x => x.NUnitTaskForNunitV3("TestProjectName3"));
1
2
context.CreateTarget("Example")`
   .AddCoreTask(x => x.Build("MySolution.sln").Configuration("Release");

flubu example --configuration=Debug

flubu 将执行 dotnet build MySolution.sln --configuration Debug

1
2
    dotnet tool install --global FlubuCore.GlobalTool
    flubu compile
1
    context.WaitForDebugger();

FlubuCore 交互模式

  • 使用 FlubuCore 自定义分析器(FlubuCore custom analyzers)增强开发体验。

执行中的 FlubuCore 分析器

入门

FlubuCore 用起来非常简单:-) 而且她的文档也非常完整。

FlubuCore 文档 中的入门一章将帮助你立即设置你的第一个 FlubuCore 构建。

可在构建脚本的原理 一章中查阅 FlubuCore 提供的完整功能列表。

一旦你定义了构建与部署脚本(build and deployment scripts),以下 Wiki 张杰将解释如何运行它们:

范例

除了 Wiki 的详细介绍外,FlubuCore 还提供了大量与真实情况相若的范例。这些例子可以在独立仓库 Examples repository 中找到。

这些示例有助于你快速入门 FlubuCore:

这些示例有助于你快速入门 FlubuCore:

  • .NET Framework 构建示例 - Example covers versioning, building the project, running tests, packaging application for deployment.

  • .NET Core 构建示例 - Example covers versioning, building the project, running tests, packaging application for deployment.

  • 部署脚本示例 - Example shows how to write simple deployment script.

  • Open source library example - Example covers versioning, building the project, running tests and publishing nuget package. It also covers how to run build script on Appveyor and Travis CI.

疑惑?

Join the chat at https://gitter.im/FlubuCore/Lobby

贡献

请移步阅读 CONTRIBUTING.md.

如何作出贡献

  • 为本项目做推广。
  • 如果你对本项目感兴趣,请在右上角点击 star,以便壮大我们的社区。
  • 改进文档
  • 反馈、修正 Bug。
  • 实现新功能。
  • 讨论如何进一步改进项目。
  • 改善项目的现有实现、性能等。

Further Development

If you find FlubuCore useful (you feel it helps you on the daily basis) you can support further development by buying us a coffee (or become a backer or sponsor). Sometimes it's hard to stay awake till midnight implementing new features, coffee helps us with that. We would really appreciate your support. Money from sponsorship will also be used for the promotion of the project. If you are a backer or a sponsor you can also request for a new feature or ask for support. These issues will be handled with highest priority.

Backers and Sponsors

OpenCollective OpenCollective

更新日志与路线图

详细变更记录与示例请参阅变更日志

FlubuCore 路线图请翻阅项目里程碑