FlubuCore

Travis NuGet Badge Gitter Twitter Member project of .NET Foundation 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 local or global tool flubu Default

功能与优势

  • 直观,易学。C#、流畅的 API 设计和 IntelliSense,使复杂脚本的构建变得举重若轻。
[FromArg("nugetKey", "Nuget api key for publishing Flubu nuget packages.")]
public string NugetApiKey { get; set; }

protected override void ConfigureTargets(ITaskContext context)
{
    var pack = context.CreateTarget("Pack")
        .SetDescription("Prepare's nuget package.")
        .AddCoreTask(x => x.Pack()
            .NoBuild()
            .OutputDirectory(OutputDirectory)
            .WithArguments("--force"); //you can add your own custom arguments on each task

    var branch = context.BuildSystems().Travis().Branch;

    var nugetPush = context.CreateTarget("Nuget.publish")
        .SetDescription("Publishes nuget package.")
        .DependsOn(pack)
        .AddCoreTask(x => x.NugetPush($"{OutputDirectory}/NetCoreOpenSource.nupkg")
            .ServerUrl("https://www.nuget.org/api/v2/package")
             .ApiKey(NugetApiKey)
        )
        .When((c) => c.BuildSystems().RunningOn == BuildSystemType.TravisCI
                     && !string.IsNullOrEmpty(branch)
                     && branch.EndsWith("stable", StringComparison.OrdinalIgnoreCase));
}
  • 内置大量常用任务,如运行测试、versioning、管理 ISS、创建部署包(deployment packages)、发布 NuGet 包、docker 任务、 sql tasks, git tasks, 执行 PowerShell 脚本等。
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"));
context.CreateTarget("DoExample")
        .Do((c) =>
        {
            //// write your awesome code.
            File.Copy("NotSoAwesome.txt", Path.Combine(OutputDirectory, "JustAnExample.txt") );
            //// Access flubu built in tasks in DO if needed.
            c.Tasks().GenerateT4Template("example.TT").Execute(c);                
        })
        .AddTask(x => x.CompileSolutionTask())
        .Do(NuGetPackageReferencingExample);
  • 当脚本与项目文件一起使用时会自动加载程序集引用和 NuGet 包。当脚本单独执行(譬如在生产环境中使用 FlubuCore 脚本进行部署)时,可在特性(attributes)中添加引用(references)。
[NugetPackage("Newtonsoft.json", "11.0.2")]
[Assembly(".\Lib\EntityFramework.dll")]
public class BuildScript : DefaultBuildScript
{
   public void NuGetPackageReferencingExample(ITaskContext context)
    {
        JsonConvert.SerializeObject("Example");
    }
}
 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"));
    }
 }
 public class SimpleScript : DefaultBuildScript
 {
    [FromArg("c", "The configuration to use for building the project.")]
    public string Configuration { get; set; } = "Release"

    [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("build")
            .AddCoreTask(x => x.Build()
                .Configuration(Configuration)
                .ForMember(x =>  x.Framework("net462"), "f", "The target framework to build for.")); 
    }
}
  flubu build -c=Debug -f=netcoreapp2.0
    public class ExampleFlubuPluginTask : TaskBase<int, ExampleFlubuPluginTask>
    {
        protected override int DoExecute(ITaskContextInternal context)
        {
            // Write your task logic here.
            return 0;
        }
    }
    context.CreateTarget("Run.Tests")
        .AddTaskAsync(x => x.NUnitTaskForNunitV3("TestProjectName1"))
        .AddTaskAsync(x => x.NUnitTaskForNunitV3("TestProjectName1"))
        .AddTaskAsync(x => x.NUnitTaskForNunitV3("TestProjectName3"));
context.CreateTarget("Example")`
   .AddCoreTask(x => x.Build("MySolution.sln").Configuration("Release");

flubu example --configuration=Debug

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

    dotnet tool install --global FlubuCore.GlobalTool
    flubu compile
    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 路线图请翻阅项目里程碑

Acknowledgements

  • Special thanks to @ironcev for greatly improving readme and for giving some valuable advices.
  • Special thanks to @alexinea for translating whole documentation to Chinese.
  • Special thanks to @huanlin for writing blogs about FlubuCore in Traditional Chinese and for translationg them to English.

.NET Foundation

This project is supported by the .NET Foundation.