Creating Simple Tasks in .NET with Bullseye

How many times have you created a console application to run specific tasks in .NET?  These tasks could be processing a file, making some HTTP call to an external service or even helping in your build process.  Ultimately ending up with a collection of different tasks which often have dependencies on each other.

I just discovered a project called Bullseye by Adam Ralph which really feels like a simple task runner.  But better yet, is just a library you add to your own console application and not its own process itself.

Bullseye

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

Bullseye can be used to write targets that do anything. It is not coupled to building .NET projects.

Platform support: .NET Standard 1.3 and upwards.

Examples

The simplest example which is described on the Bullseye readme is similar to as follows:

There’s really only two components needed.  Define your target(s) using the Target() methods and then specify which targets to run via RunTargets()

If you do not specify a target to run then the “default” target is used.

If you simply run dotnet run will produce the output:

This would have been the equivalent of running dotnet run default

Dependencies

Here’s a simple example of having one target depend on another.  In one target I’m hitting a service to get the exchange rate from CAD to USD.  In another, I want to save that rate to a file.

When run with dotnet run saveexchangerate

Now if I just want to get the rate but not save it, I could just run dotnet run getexchangerate

Targets

How are you handling running small tasks/targets?  Simple console applications?  Using the new global tools? Let me know on Twitter or in the comments.

Enjoy this post? Subscribe!

Subscribe to our weekly Newsletter and stay tuned.