Bennewitz.Ninja.AutoVersioning 2026.2.522

dotnet add package Bennewitz.Ninja.AutoVersioning --version 2026.2.522
                    
NuGet\Install-Package Bennewitz.Ninja.AutoVersioning -Version 2026.2.522
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Bennewitz.Ninja.AutoVersioning" Version="2026.2.522">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Bennewitz.Ninja.AutoVersioning" Version="2026.2.522" />
                    
Directory.Packages.props
<PackageReference Include="Bennewitz.Ninja.AutoVersioning">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Bennewitz.Ninja.AutoVersioning --version 2026.2.522
                    
#r "nuget: Bennewitz.Ninja.AutoVersioning, 2026.2.522"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Bennewitz.Ninja.AutoVersioning@2026.2.522
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Bennewitz.Ninja.AutoVersioning&version=2026.2.522
                    
Install as a Cake Addin
#tool nuget:?package=Bennewitz.Ninja.AutoVersioning&version=2026.2.522
                    
Install as a Cake Tool

Bennewitz.Ninja.AutoVersioning

A Roslyn incremental source generator that injects assembly metadata attributes and build-time constants into .NET projects at compile time — no AssemblyInfo.cs, no disk writes, full IDE caching.

NuGet CI

Requirements

.NET SDK 6.0 or later (requires Roslyn 4.0+ for IIncrementalGenerator support). The consuming project may target any framework — .NET Framework 4.x, .NET Standard, .NET 6+, etc.

Quick Start

1. Add the package:

<PackageReference Include="Bennewitz.Ninja.AutoVersioning" Version="x.x.x" />

2. Enable the generator in your root Directory.Build.props (or any .props / .csproj imported by your build):

<PropertyGroup>
  <GenerateAutoVersionedAssemblyInfo>true</GenerateAutoVersionedAssemblyInfo>
  <AssemblyCompany>YourCompany</AssemblyCompany>
  <AssemblyProduct>YourProduct</AssemblyProduct>

  
  <CommitSha Condition="'$(CommitSha)' == ''">$(GITHUB_SHA)</CommitSha>
  <IsContinuousIntegration>$(GITHUB_ACTIONS)</IsContinuousIntegration>
  <PublicVersion Condition="'$(PublicVersion)' == ''">$(MY_VERSION_VAR)</PublicVersion>
</PropertyGroup>

Note: The package's auto-imported Build.props automatically suppresses the 8 SDK-generated attributes that conflict with this generator (e.g. AssemblyVersion, AssemblyCopyright). It uses granular per-attribute suppressions rather than <GenerateAssemblyInfo>false</GenerateAssemblyInfo>, which means InternalsVisibleTo and all other SDK-generated attributes continue to work normally. Do not add <GenerateAssemblyInfo>false</GenerateAssemblyInfo> yourself — it will break InternalsVisibleTo.

A ready-to-use template is available at Directory.Build.props.template.

3. Build. The generator runs automatically — no further setup needed.

Tip: View the generated files in your IDE under Dependencies → Analyzers → *SourceGenerators.


Generated Output

Given a build on 2026-04-29 at 14:35 UTC for company Acme Corp, product Acme App, commit abc1234def, and public version 3.1.0:

AutoVersionedAssemblyInfo.g.cs

using System.Reflection;
using System.Runtime.CompilerServices;

[assembly: AssemblyDescription("Assembly Version: 2026.2.429.1435")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCompany("Acme Corp")]
[assembly: AssemblyProduct("Acme App v2026.2.429.1435")]
[assembly: AssemblyCopyright("Copyright 2026 [Release]")]
[assembly: AssemblyVersion("2026.2.429.1435")]
[assembly: AssemblyFileVersion("2026.2.429.1435")]
[assembly: AssemblyInformationalVersion("Commit♥: abc1234def")]
[assembly: AssemblyMetadata("CommitSha", "abc1234def")]
[assembly: AssemblyMetadata("GITHUB_SHA", "abc1234def")]
[assembly: AssemblyMetadata("PublicVersion", "3.1.0")]

DirectoryBuildInfo.g.cs

// <auto-generated/>
namespace Bennewitz.Ninja.AutoVersioning
{
    /// <summary>Build-time constants generated by the source generator.</summary>
    public static class DirectoryBuildInfo
    {
        public const string BuildRelease = "Version 2026.2.429.1435 [built 4/29/2026 2:35:00 PM (UTC)]";
    }
}

Use DirectoryBuildInfo.BuildRelease wherever you need the build version at runtime — error trackers, log enrichment, health endpoints — without reading environment variables.


Configuration Reference

MSBuild Property Description Required
GenerateAutoVersionedAssemblyInfo Set to true to enable the generator Yes
AssemblyCompany Value for [assembly: AssemblyCompany(...)] Yes
AssemblyProduct Value for [assembly: AssemblyProduct(...)] Yes
CopyrightHolder Name shown in the copyright attribute — defaults to AssemblyCompany if omitted No
CommitSha Git commit SHA No
IsContinuousIntegration true on CI runs No
PublicVersion Your app's public-facing version string No
Configuration Debug / Release — set automatically by MSBuild Auto

CI Provider Mappings

Provider Commit SHA CI flag
GitHub Actions $(GITHUB_SHA) $(GITHUB_ACTIONS)
GitLab CI $(CI_COMMIT_SHA) $(GITLAB_CI)
Bitbucket Pipelines $(BITBUCKET_COMMIT) $(CI)

Version Format

The generator uses CalVer: YEAR.QUARTER.MMDD.HHmm

Part Example Meaning
Major 2026 Calendar year
Minor 2 Quarter (1–4)
Build 429 Month + day (MMdd as integer)
Revision 1435 Hour + minute (HHmm as integer)

How It Works

This is a modern C# IIncrementalGenerator. Compared to legacy ISourceGenerator approaches it:

  • Runs entirely in-memory — zero files written to disk
  • Uses the Roslyn caching pipeline — the IDE (Rider, Visual Studio) only re-runs the generator when its inputs change, eliminating background compilation loops
  • Reads MSBuild properties via AnalyzerConfigOptionsProvider — safe, no direct environment variable reads

The package auto-imports Build.props via NuGet, which declares CompilerVisibleProperty items and suppresses the SDK's default AssemblyInfo generation (preventing CS0579 duplicate attribute errors when the generator is enabled).

Diagnostics

ID Severity Description
BAUTOVERSIONING00 Warning Generator is installed but GenerateAutoVersionedAssemblyInfo is not set to true (single-line signal)
BAUTOVERSIONING01 Warning Generator threw an unexpected exception
BAUTOVERSIONING02 Error AssemblyCompany is not configured
BAUTOVERSIONING03 Error AssemblyProduct is not configured
BAUTOVERSIONING04 Warning Multi-line setup snippet emitted alongside BAUTOVERSIONING00 — shows the required Directory.Build.props configuration

Building Locally

Requires PowerShell 7+ and the .NET SDK.

./Pack.ps1

The script prompts for a version (defaults to CalVer YYYY.Q.MMDD) and produces .nupkg files in packages/Debug/ and packages/Release/.


License

MIT © 2026 Brian Bennewitz

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2026.2.522 505 5/21/2026
2026.2.521 97 5/21/2026
2026.2.515 101 5/15/2026
2026.2.501 142 5/1/2026
2026.2.429 145 4/29/2026