$ show adamralph/minver
MinVer is a minimalist versioning tool for .NET projects that derives version numbers from Git tags according to SemVer 2.0. It operates as both an MSBuild package (MinVer) and a standalone CLI tool (minver-cli). The core logic in MinVer.Lib walks the Git commit history from the current HEAD backward to find the latest version tag. If the current commit is tagged, that version is used as-is; otherwise, it optionally increments the version (patch by default) and appends a height (number of commits since the last tag) as pre-release identifiers. The library handles tag prefixes, custom auto-increment strategies, minimum major/minor overrides, build metadata, and height suppression. The CLI tool wraps this logic with System.CommandLine argument parsing and environment variable support, while the MSBuild package integrates directly into the .NET build pipeline, setting standard version properties (AssemblyVersion, FileVersion, PackageVersion, etc.). The repository is well-organized with a clear separation between library, CLI, and build package, and includes extensive unit and integration tests that actually create Git repositories to verify behaviour. The code demonstrates high craftsmanship with async Git operations, clean error handling, and a modular design that makes the core versioning algorithm reusable.
The LLM identified 5 files worth highlighting for reuse:
The central algorithm for deriving a version from Git history. It takes a working directory, tag prefix, minimum major/minor, build metadata, auto-increment strategy, default pre-release identifiers, and a flag to ignore height. It uses Git to get the HEAD commit, walks the commit graph (using a stack) to find the latest version tag (or root commit), and returns a Version object. The logic for handling height, auto-increment, and minimum major/minor satisfaction is cleanly separated. This class is the core reusable componentβany tool that needs to derive a version from Git tags can extract this method.
Extends NuGet's SemanticVersion to add height tracking and methods like WithHeight, AddBuildMetadata, Satisfying (for minimum major/minor). It is immutable and provides serialization via ToString. This is a clean, self-contained value object that encapsulates version logic beyond what NuGet.Versioning provides. Reusable in any .NET project needing version calculation with height.
Provides static async methods to check if a directory is a Git working directory (using git status --porcelain), get the HEAD commit with its parents (via git log), and list all tags (via git show-ref --tags --dereference). It parses the raw output and builds a graph of Commit objects. This is a thin, well-tested abstraction over Git commands that can be reused by other tools needing Git commit graph traversal.
A helper that runs a Git process asynchronously, capturing stdout/stderr and throwing a custom NoGitException if Git is not found. It uses TaskCompletionSource for exit notification and logs trace output. This is a reusable pattern for running any command-line tool with proper async handling and error reporting.
Encapsulates all configuration options for MinVer, with TryParse methods for both command-line arguments and environment variables. For the CLI, it implements a 'mask' pattern where command-line options override environment variable defaults, allowing partial overrides. This is a clean design pattern for merging multiple configuration sources.