Sponsor: Do you build complex software systems? See how NServiceBus makes it easier to design, build, and manage software systems that use message queues to achieve loose coupling. Get started for free.
Who doesn’t love cake? There are a ton of existing addins for Cake, but you may run into a situation where you want to create your own cake add in. Here’s how! Note: If you have no idea what Cake is, check out my intro to Automating Builds with Cake (C# Make) post first.AppSettings Replacer
In my case I wanted to replace some values in the appSettings of an app.config. There are already a couple existing ways to do this, such as the XdtTransform , however I wanted to give it a shot and explore how to create a cake addin. Turns out it’s crazy simple to create an addin. The minimum you need to know are theICakeContext
and the CakeMethodAlias
attribute.
ICakeContext and CakeMethodAlias
First you need to reference the Cake.Core nuget package.Install-Package Cake.CoreNext thing is to create an extension method off of
ICakeContext
with the CakeMethodAlias
as an attribute.
For my example, the body of the extension method will be replacing a value for a specified key in the <appSettings> section of an app/web.config.