Summary

Cake’s main purpose is to use C# to write your build logic. It’s similar to RAKE, FAKE.

Cake web site has pretty good documentation about its features and usage. I will test only following:

  • Install Cake
  • Set up VS Code
  • Demo how Cake manages dependencies when you need to write code in C#

Installation

dotnet tool install --global cake --version 0.32.1

You may also use Cake bootstrap script to install and execute.

Get VS Code to work

You need 2 VS Code plugins: OmniSharp and Cake. You can follow the instructions there to get them installed.

To get IntelliSense to work, you need to create build.cake file in the root of your VS Code project, then go to menu View -> Command Pallette, type in Cake and select “Cake: add tool from nuget”, then “Cake.Bakery”, then select the most recent version.

How Cake store downloaded dependencies

  • Cake creates sub directory called “tools” in the directory where Cake scripts are stored
  • Cake does not share nuget download with other projects

Notes on the code

Source code

I used multiple files to make it more readable.

  • build.cake: build script with task definition
  • hierarchicalXml.cake: build script with task definition. It is a quick demo of how easy to create an XML document with Linq XML, Microsoft is bringing something similar to JSON in dotnet core 3.
  • query2csv.cake: C# Postgres query code copied from other projects.

Testing

Before you run, please read Lab setup, make sure Postgres container is running.

Run the following tests:

  • dotnet cake ./build.cake
  • dotnet cake ./hierarchicalXml.cake