Faithlife.Build

Faithlife.Build is a build automation system using C# build scripts.

Overview

This library allows developers to use C# to write build scripts. It is similar to Cake and NUKE, but simpler, providing a thin wrapper over some of the libraries acknowledged below.

Most importantly, since the build script is a full-fledged .NET Core app with access to any compatible NuGet package, you can do just about anything, in a language and framework you already know well.

Usage

To use this library for your automated build, create a .NET Core Console App project in tools/build that references the latest Faithlife.Build NuGet package. Optionally add the project to your Visual Studio solution file. See Build.csproj for an example project; there are project properties in that file that you may need for everything to work as expected.

The Main method of the console app should call BuildRunner.Execute with the args and a delegate that defines the build targets and any desired command-line options by calling methods on the provided BuildApp.

using Faithlife.Build;
using static Faithlife.Build.DotNetRunner;

internal static class Build
{
    public static int Main(string[] args) => BuildRunner.Execute(args, build =>
    {
        build.Target("build")
            .Describe("Builds the solution")
            .Does(() => RunDotNet("build", "-c", "Release", "--verbosity", "normal"));
    });
}

Perform the build by calling dotnet run on the build project, which is most easily done from a simple bootstrapper, typically named build.cmd (for Windows) and/or build.sh (for non-Windows).

Consult the full reference documentation for additional details.

Create .NET Targets

To create standard targets for a .NET build, call DotNetBuild.AddDotNetTargets with custom settings as needed. See Build.cs for an example.

The supported targets include:

  • clean : Deletes all build output.
  • restore : Restores NuGet packages.
  • build : Builds the solution.
  • test : Runs the unit tests.
  • package : Builds NuGet packages.
  • publish : Publishes NuGet packages and documentation.

The supported command-line options include:

  • --configuration <name> : The configuration to build (default Release).
  • --platform <name> : The solution platform to build.
  • --version-suffix <suffix> : Generates a prerelease NuGet package.
  • --nuget-output <path> : Directory for the generated NuGet package (default release).
  • --trigger <name> : The git branch or tag that triggered the build.
  • --build-number <number> : The automated build number.
  • --no-test : Skip the unit tests.

The supported DotNetBuildSettings include:

  • SolutionName : The name of the solution file; defaults to the only solution in the directory.
  • SolutionPlatform : The default solution platform to build.
  • NuGetSource : The NuGet source to which to push packages, if not the standard source.
  • DocsSettings : Used to generate Markdown documentation from XML comments.
  • MSBuildSettings : Set to use MSBuild instead of dotnet to build the solution.

For details on exactly what each target does and how the settings and command-line options affect the build, read the source code.

Acknowledgements

Special thanks to the libraries and tools used by Faithlife.Build:

Also thanks to Paul Knopf for this article, which inspired us to think beyond Cake.