I’ve looked at using Cake (C# Make) for build automation in C#. The basics were to compile a solution/project using MSBuild and then run our automated tests with xUnit.
Another common set of tasks that are performed in a build pipeline are:
- Create a NuGet package
- Push the NuGet package to Octopus Deploy
- Create an Octopus Deploy Release
First thing we need to do is to create a NuGet package. You have a couple options here, one is to create a nuspec and invoke the Nuget.exe to create your package. I’m going to choose an alternative which is to use the built-in Nuget support to generate our NuGet package all within code.
I’ve added a new “Pack” task which is called from our “Default” task. This task will create our NuGet package when we run our build.ps1
Now when we run our build, we can see the Pack task was created our NuGet package: “CakeDemo.0.0.0.1.nupkg”
Cake has built-in support for Octopus Deploy. To get started, you need to include the OctopusTools in your build.cake file.
We can use the OctoPush method for pushing your newly created NuGet package to the Octopus Deploy NuGet Server.
Now that our NuGet package has been pushed to Octopus Deploy, we can create a release using the OctoCreateRelease method.
To tie this all together, we need to make sure that our Default task will run our OctoPush and OctoRelease tasks. Here is our final build.cake file
Now when we run our build we can see that our Octopus Deploy release was created.
There are a ton of built-in tasks and the Cake documentation is really good. Hopefully you can see the benefits of having a build script in code which can be version controlled and run anywhere.
Let me know if you have any comments related to Cake or any other build automation tooling either in comments or on twitter.
The source code for this demo is available on GitHub.