构建工具的选择:MSBuild,NANT还是其他什么?

DSa*_*ura 6 msbuild nant tfs

我在公司做自动化.我们是一个C#研讨会.目前我正在进行自动构建.NANT是流量控制工具.虽然NANT没有积极开发(20126月发布的最后一个二进制文件并且github repo未激活),但MSBuild更好.因此,我更喜欢MSBuild,但退休的NANT仍然值得怀疑 - 成本是多少?

我提出了一些优点和缺点,但我知道集体智慧更好.谢谢你的帮助!


更新:我已经阅读了这个问题,但第二个答案引起了我的担忧.在构建机器上有多个.NET框架,会不会很麻烦?


的MSBuild

优点:

  • 商业支持
  • 社区在增长
  • 与VS和TFS集成
  • 跟上.Net的步伐

缺点:

  • 重写当前脚本
  • 人们不熟悉

NANT

优点:

  • 已经在使用了
  • 熟悉的人

缺点:

  • 长期未更新(自2012年起)
  • 社区不活跃
  • 缺乏新的.Net支持

Sta*_*n88 5

我们写了FlubuCore(改写了Flubu).它是一个开源的C#库,用于使用C#代码构建项目和执行部署脚本.

我看到flubu的主要优点是:

  • .Net核心支持.
  • 易于学习和使用,因为您完全使用C#编写构建脚本.
  • 流畅的界面和智能感.
  • 相当多的内置任务(编译,运行测试,管理iis,创建部署包,发布nuget包,执行powershell脚本......)
  • 在脚本中编写自己的自定义c#代码并执行它.
  • 使用RunProgramTask在脚本中运行任何外部程序或命令.
  • 在buildscript中引用任何.net库或c#源代码文件.现在还可以选择在构建脚本中引用nuget包.
  • 编写测试,调试构建脚本..
  • 在任何其他.net应用程序中使用flubu任务.
  • Web api可用于flubu.对远程自动部署很有用.
  • 编写您自己的flubu任务并扩展flubu流畅的界面.

你可以在nuget上找到flubu:

如果你需要.net项目,请搜索FlubuCore.Runner

如果你需要for.net核心项目,请搜索dotnet-flubu

如何在.net中使用flubu的示例:

protected override void ConfigureBuildProperties(IBuildPropertiesContext context) {
 context.Properties.Set(BuildProps.NUnitConsolePath,
  @ "packages\NUnit.ConsoleRunner.3.6.0\tools\nunit3-console.exe");
 context.Properties.Set(BuildProps.ProductId, "FlubuExample");
 context.Properties.Set(BuildProps.ProductName, "FlubuExample");
 context.Properties.Set(BuildProps.SolutionFileName, "FlubuExample.sln");
 context.Properties.Set(BuildProps.BuildConfiguration, "Release");
}

protected override void ConfigureTargets(ITaskContext session) {
 var loadSolution = session.CreateTarget("load.solution")
  .SetAsHidden()
  .AddTask(x => x.LoadSolutionTask());

 var updateVersion = session.CreateTarget("update.version")
  .DependsOn(loadSolution)
  .SetAsHidden()
  .Do(TargetFetchBuildVersion);

 session.CreateTarget("generate.commonassinfo")
  .SetDescription("Generates common assembly info")
  .DependsOn(updateVersion)
  .TaskExtensions().GenerateCommonAssemblyInfo()

 var compile = session.CreateTarget("compile")
  .SetDescription("Compiles the solution.")
  .AddTask(x => x.CompileSolutionTask())
  .DependsOn("generate.commonassinfo");

 var unitTest = session.CreateTarget("unit.tests")
  .SetDescription("Runs unit tests")
  .DependsOn(loadSolution)
  .AddTask(x => x.NUnitTaskForNunitV3("FlubuExample.Tests"));

 session.CreateTarget("abc").AddTask(x => x.RunProgramTask(@ "packages\LibZ.Tool\1.2.0\tools\libz.exe"));

 session.CreateTarget("Rebuild")
  .SetDescription("Rebuilds the solution.")
  .SetAsDefault()
  .DependsOn(compile, unitTest);
}

//// Some custom code
public static void TargetFetchBuildVersion(ITaskContext context) {
 var version = context.Tasks().FetchBuildVersionFromFileTask().Execute(context);

 int svnRevisionNumber = 0; //in real scenario you would fetch revision number from subversion.
 int buildNumber = 0; // in real scenario you would fetch build version from build server.
 version = new Version(version.Major, version.Minor, buildNumber, svnRevisionNumber);
 context.Properties.Set(BuildProps.BuildVersion, version);
}
Run Code Online (Sandbox Code Playgroud)

如何在.net核心中使用flubu的示例

public class MyBuildScript : DefaultBuildScript
{
    protected override void ConfigureBuildProperties(IBuildPropertiesContext context)
    {
        context.Properties.Set(BuildProps.CompanyName, "Flubu");
        context.Properties.Set(BuildProps.CompanyCopyright, "Copyright (C) 2010-2016 Flubu");
        context.Properties.Set(BuildProps.ProductId, "FlubuExample");
        context.Properties.Set(BuildProps.ProductName, "FlubuExample");
        context.Properties.Set(BuildProps.SolutionFileName, "FlubuExample.sln");
        context.Properties.Set(BuildProps.BuildConfiguration, "Release");
    }

    protected override void ConfigureTargets(ITaskContext context)
    {
        var buildVersion = context.CreateTarget("buildVersion")
            .SetAsHidden()
            .SetDescription("Fetches flubu version from FlubuExample.ProjectVersion.txt file.")
            .AddTask(x => x.FetchBuildVersionFromFileTask());

        var compile = context
            .CreateTarget("compile")
            .SetDescription("Compiles the VS solution and sets version to FlubuExample.csproj")
            .AddCoreTask(x => x.UpdateNetCoreVersionTask("FlubuExample/FlubuExample.csproj"))
            .AddCoreTask(x => x.Restore())
            .AddCoreTask(x => x.Build())
            .DependsOn(buildVersion);

        var package = context
            .CreateTarget("Package")
            .CoreTaskExtensions()
            .DotnetPublish("FlubuExample")
            .CreateZipPackageFromProjects("FlubuExample", "netstandard2.0", "FlubuExample")
            .BackToTarget();

    //// Can be used instead of CreateZipPackageFromProject. See MVC_NET4.61 project for full example of PackageTask
    //// context.CreateTarget("Package2").AddTask(x =>   
             x.PackageTask("FlubuExample"));

         var test = context.CreateTarget("test")
            .AddCoreTaskAsync(x => x.Test().Project("FlubuExample.Tests"))
            .AddCoreTaskAsync(x => x.Test().Project("FlubuExample.Tests2"));   

         context.CreateTarget("Rebuild")
             .SetAsDefault()                 
             .DependsOn(compile, test, package);
}
Run Code Online (Sandbox Code Playgroud)

}

详细的演示文稿和文档可以在这里找到:https: //github.com/flubu-core/flubu.core

你可以在这里找到完整的例子:https: //github.com/flubu-core/examples


DSa*_*ura 2

感谢您的所有回答。由于我们是 C# 工作室,因此决定使用 Cake。