Table of Contents

GitVersion

Integrates GitVersion to provide automatic build ID and version numbers based on your Git history. Use it when versions should come from tags and branches instead of Directory.Build.props.

Package: Invex.Atom.Module.GitVersion

Installation

dotnet add package Invex.Atom.Module.GitVersion

Usage

Implement IGitVersion and enable the corresponding build options:

[BuildDefinition]
[GenerateEntryPoint]
internal partial class Build : BuildDefinition, IGitVersion
{
    public override IReadOnlyList<IBuildOption> Options =>
    [
        BuildOptions.GitVersion.ProvideBuildId,
        BuildOptions.GitVersion.ProvideBuildVersion,
    ];

    // BuildId and BuildVersion are now sourced from GitVersion.
}

What It Does

When IGitVersion is implemented, the module registers:

  • GitVersionBuildIdProvider as IBuildIdProvider
  • GitVersionBuildVersionProvider as IBuildVersionProvider

These replace the default providers, so BuildId and BuildVersion in your IBuildInfo are automatically populated from GitVersion output.

Important

The providers only activate when the corresponding flag is enabled in Options. If IGitVersion is implemented but a flag is missing, resolving BuildId / BuildVersion throws an error telling you to enable the flag. This lets you opt in to GitVersion for the version, the ID, or both.

Prerequisites

The providers install and run a pinned version of the GitVersion.Tool global .NET tool (currently 6.8.2), so the build doesn't break when a new GitVersion major version changes its command-line arguments or output. If a different version is installed globally, it is replaced with the pinned version the first time GitVersion is needed.

Configure it via GitVersion.yml in your repository root, using the configuration format of the pinned GitVersion version.

See also