Skip to content

Versioning Phase 7 — swap NBGV for native versioning (SDK task + module, tool rewire, ThisAssembly) #296

@rdeago

Description

@rdeago

Sub-issue of #267. Depends on Phases 4 (#293), 5 (#294), 6 (#295). The atomic swap: this is the single point where the version source flips from NBGV to native, so it lands as one change — no PR may ship with two active versioning systems. The repo's own migration completes in a post-publish tail (below) so self-hosting never breaks.

Scope

SDK — native build-time versioning

  • New Versioning SDK module at src/Buildvana.Sdk/Modules/Versioning/Module.targets, replacing NerdbankGitVersioning. Auto-detected by the presence of a VERSION file; projects without one build unchanged (stub/opt-out target). Rename UseNerdbankGitVersioningUseVersioning, keeping a warned alias for the old property.
  • New build-time task in Buildvana.Sdk.Tasks: reads VERSION + buildvana.json (via Buildvana.Core.Configuration), runs VersioningService in-process (hand-wired ctor injection, no container) using the engine-backed IReporter from Phase 5, and sets $(Version), $(AssemblyVersion), $(FileVersion), $(AssemblyInformationalVersion) honoring versioning.assemblyVersionPrecision. Uses the single LibGit2Sharp height calculator — no git CLI dependency, no "git absent" error.

SDK — ThisAssembly version constants

  • The Versioning module enables GenerateThisAssemblyClass and contributes default ThisAssemblyConstants for the version fields we consume (at minimum AssemblyVersion, FileVersion, informational/semver/simple strings, IsPublicRelease, IsPrerelease), feeding the Phase 6 generator. This replaces NBGV's ThisAssembly end-to-end. (EnableDefaultThisAssemblyConstants=false still suppresses them.)

Tool — rewire onto the library

  • Delete the tool's own versioning types (VersionSpec, VersionSpecChange, VersionFile, VersionIncrement, VersionService) and route the existing version consumers (the release flow) through Buildvana.Core.Versioning. Remove the nbgv subprocess + JSON-parsing path; the tool reads VERSION.
  • Git height stays in the library, not GitService; GitService keeps pure git-access concerns (identity, credentials, URL, current branch). Decide how the tool hands a repo/branch to the calculator.
  • (The standalone bv version show/advance command stays Phase 8; here we only rewire existing consumers and keep VERSION read/write available via the library.)

NBGV removal

  • Delete Modules/NerdbankGitVersioning/, remove the NBGV BV_PackageVersion injection from PackageVersions.props, and drop pathFilters (warn if non-empty).

Packaging spike (do first)

  • Verify the build-time task loads LibGit2Sharp + its native assets inside the MSBuild task host under both dotnet build and .NET-Framework msbuild.exe (out-of-proc task host); package LibGit2Sharp's managed + runtimes/<rid>/native assets into Buildvana.Sdk, cribbing NBGV's layout. A surprise here reshapes the phase, so de-risk before building on it.

Self-host transition (in this PR)

  • Add the repo's own VERSION (+ any remaining versioning keys in buildvana.json), kept in sync with the retained version.json. version.json and nbgv are retained for now because the repo still self-hosts on the last published (NBGV) SDK.

Post-publish tail (follow-up, after the new SDK is published)

  • Roll the self-host SDK pin to the newly published version; then remove version.json, the nbgv entry from .config/dotnet-tools.json, and any transitional NBGV scaffolding. Must land after publish so the build never lacks what its SDK expects.

Acceptance criteria

  • A C# project using Buildvana.Sdk with a VERSION file gets correct $(Version)/$(AssemblyVersion)/$(FileVersion)/$(AssemblyInformationalVersion) via plain dotnet build (not just bv); precision honors assemblyVersionPrecision; a generated ThisAssembly carries the version constants.
  • Height increases monotonically within a version line and resets at each VERSION change; the overall version never regresses. No system git required; detached HEAD ⇒ non-public-release.
  • NBGV no longer appears in the SDK package, its injection, or the tool; UseNerdbankGitVersioning still works with a deprecation warning; projects without a VERSION build as before.
  • bv's release flow computes versions natively without nbgv.
  • The packaging spike passes under both MSBuild hosts.
  • dotnet bv build self-hosts throughout (old published SDK + retained version.json), and again after the post-publish tail.
  • CHANGELOG: Unreleased with **BREAKING CHANGE** entries for NBGV removal, the UseNerdbankGitVersioningUseVersioning rename, the version.jsonVERSION migration, and pathFilters removal; plus the migration note.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement[issue/PR] requests / implements new or improved functionality.refactor[issue/PR] requests / implements a refactor of existing code without affecting functionality.
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions