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

8

我在公司做自动化。我们是一个C#的工作室。目前,我正在从事自动构建方面的工作。NANT是流程控制工具。虽然NANT已经没有得到积极开发(上一个二进制版本发布于2012年6月且github存储库不再活跃),但MSBuild更好。因此,我更喜欢使用MSBuild,但是是否放弃NANT仍然有待商榷-成本是多少?

我列出了一些优缺点,但我知道集体智慧更好。感谢您的帮助!


更新: 我已经阅读了这个问题,但是第二个答案让我有些担忧。构建机器上有多个.NET框架,会有麻烦吗?


MSBuild

优点:

  • 商业支持
  • 社区正在增长
  • 与VS和TFS集成
  • 跟进.Net

缺点:

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

NANT

优点:

  • 已经在使用中
  • 人们熟悉

缺点:

  • 很长时间没有更新(自2012年以来)
  • 社区不活跃
  • 缺乏新的.Net支持

可能是NAnt或MSBuild,应该在何时选择?的重复问题。 - Giulio Vian
PSake对您也许很有趣:https://github.com/psake/psake - jessehouwing
1
感谢所有的回答。我们决定使用Cake,因为我们是一个C#工作室。 - CSakura
@DSakura 发布一个答案并接受它来关闭这个问题。 - Lex Li
3个回答

7
我们编写了FlubuCore(重新编写的Flubu)。它是一个开源的C#库,用于使用C#代码构建项目和执行部署脚本。Flubu的主要优势包括:
- .Net Core支持。 - 写构建脚本完全使用C#,易学易用。 - 流畅的接口和智能感知。 - 相当多的内置任务(编译、运行测试、管理iis、创建部署包、发布nuget包、执行powershell脚本等)。 - 在脚本中编写自己的自定义C#代码并执行它。 - 使用RunProgramTask在脚本中运行任何外部程序或命令。 - 在构建脚本中引用任何.NET库或C#源代码文件。现在也可以在构建脚本中引用NuGet包。 - 编写测试,调试构建脚本。 - 将flubu任务用于任何其他.NET应用程序。 - flubu提供Web API,可用于远程自动化部署。 - 编写自己的flubu任务并使用它们扩展flubu流畅接口。
您可以在NuGet上找到flubu:
- 如果您需要用于.NET项目,则搜索FlubuCore.Runner。 - 如果您需要用于.net core项目,则搜索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);
}

flubu在.NET Core中的使用示例

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);
}

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

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


看起来很有趣,如果我有时间的话我会去看看。 - CSakura

2

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


-1

有一个属性nant.settings.currentframework,用于在您拥有多个 .net 框架的情况下设置目标框架。

<property name="nant.settings.currentframework" value="net-2.0" />

根据.92版本构建:

  • nant.settings.currentframework 当前目标框架,例如“net-1.0”。
  • nant.settings.currentframework.description 已弃用。当前目标框架的描述。
  • nant.settings.currentframework.frameworkdirectory 已弃用。当前目标框架的框架目录。
  • nant.settings.currentframework.sdkdirectory 已弃用。当前目标框架的框架SDK目录。
  • nant.settings.currentframework.frameworkassemblydirectory 已弃用。当前目标框架的框架程序集目录。
  • nant.settings.currentframework.runtimeengine 已弃用。如果使用,当前目标框架的运行时引擎,例如mono.exe。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接