Configure versioning with nuke

586 Views Asked by At

When using cake, I can set which semver part I want updated:

var settings = new MinVerSettings();
settings.AutoIncrement = MinVerAutoIncrement.Major;
var minver = MinVer(settings);

That example is for minver, but the same would apply for nerdbank or gitversion.

How can I do the equivalent with nuke? The docs cover the basics only.

I use this: [MinVer] private readonly MinVer _minVer;, but am unsure what to do next.

(If you have a working sample for any of gitversion/nerdbank/minver that's fine, I'll adapt it for my needs, as it seems the basic mechanism is identical.)

2

There are 2 best solutions below

0
On

It depends on the specific tool you are using for the versioning, as its external API is different from each other (and so the tool that nuke inject into your build).

For example, with Nerdbank i can obtain the various parts of the version info like this:

 [NerdbankGitVersioning]
 readonly NerdbankGitVersioning NerdBank;

 // And on my target...
 var version = NerdBank.VersionMajor;

Anyway, keep in mind that you have the freedom to call CLI tools with nuke if the injected tools doesn't satisfy your use case. Check this:

https://nuke.build/docs/common/cli-tools/#lightweight-api

And here an example for your use case that uses this approach:

[NuGetPackage("minver", @"MinVer.dll")]
readonly Tool MinVer;
    
// And on your target...
var version = MinVer("--autoincrement major").First().Text;
1
On

This will work regardless of what else you are using (e.g. Cake, Nuke, etc.):

dotnet add package SimpleExec
using static SimpleExec.Command;

var (minver, _) = await ReadAsync("minver", "--autoincrement major");