blairconrad / bullseye

⊙ A .NET package for describing and running targets and their dependencies

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bullseye

NuGet version

Appveyor build status Azure DevOps build status CircleCI build status Cirrus CI build status GitHub build status GitLab build status Travis CI build status

Bullseye is a .NET library for describing and running targets and their dependencies.

Bullseye targets can do anything. They are not restricted to building .NET projects.

Platform support: .NET Standard 2.0 and upwards.

Quick start

  • Install the .NET Core SDK.
  • In a console:
    mkdir targets
    cd targets
    dotnet new console
    dotnet add package Bullseye
  • Using your favourite text editor or IDE, replace the contents of Program.cs with:
    using static Bullseye.Targets;
    
    class Program
    {
        static void Main(string[] args)
        {
            Target("default", () => System.Console.WriteLine("Hello, world!"));
            RunTargetsAndExit(args);
        }
    }
  • Back in your console:
    dotnet run
  • For help:
    dotnet run -- --help

Also see the async quick start.

Defining dependencies

Target("default", DependsOn("drink-tea", "walk-dog"));
Target("make-tea", () => Console.WriteLine("Tea made."));
Target("drink-tea", DependsOn("make-tea"), () => Console.WriteLine("Ahh... lovely!"));
Target("walk-dog", () => Console.WriteLine("Walkies!"));

Enumerable inputs

Target(
    "eat-biscuits",
    ForEach("digestives", "chocolate hob nobs"),
    biscuits => Console.WriteLine($"Mmm...{biscuits}! Nom nom."));
dotnet run -- eat-biscuits

Sample wrapper scripts

  • build.cmd
@echo Off
dotnet run --project targets -- %*
  • build.sh
#!/usr/bin/env bash
set -euo pipefail
dotnet run --project targets -- "$@"
  • build.ps1
$ErrorActionPreference = "Stop";
dotnet run --project targets -- $args

Command line arguments

Generally, all the command line arguments passed to Program.cs should be passed along to Bullseye, as shown in the quick start above (RunTargetsAndExit(args);). This is because Bullseye effectively provides a command line interface, with options for displaying a list of targets, performing dry runs, suppressing colour, and more. For full details of the command line options, run your targets project supplying the --help (-h/-?) option:

dotnet run --project targets -- --help
./build.cmd --help
./build.sh -h
./build.ps1 -?

You can also handle custom arguments in Program.cs, but you should ensure that only valid arguments are passed along to Bullseye. A good way to do this is to use a command line parsing package to parse your custom arguments, and pass any unrecognised arguments to Bullseye. For example:

FAQ

Can I force a pause before exiting when debugging in Visual Studio 2017 (or earlier)?

Yes! Add the following line anywhere before calling RunTargetsAndExit/RunTargetsAndExitAsync:

AppDomain.CurrentDomain.ProcessExit += (s, e) => Console.ReadKey();

Note that the common way to do this for .NET console apps is to add a line such as the following before the end of the Program.Main method:

Console.ReadKey();

This does not work after calling RunTargetsAndExit/RunTargetsAndExit because that is the final statement that will be executed.

In Visual Studio 2019 and later, .NET console apps pause before exiting by default, so none of this is required.

Who's using Bullseye?

To name a few:

Feel free to send a pull request to add your repo or organisation to this list!


Target by Franck Juncker from the Noun Project.

About

⊙ A .NET package for describing and running targets and their dependencies

License:Apache License 2.0


Languages

Language:C# 97.0%Language:Batchfile 1.5%Language:Shell 1.5%