Skip to content
Imre Pühvel edited this page Jan 3, 2021 · 4 revisions

User can configure how any supported versioning attribute value should be generated. This is can be achieved by either setting MSBuild properties directly in the .csproj-file or by creating a file named Nortal.Utilities.AssemblyVersioning.MsBuildTask.props in project root or Properties subfolder.

See the configuration file example for configurable settings.

Without any custom configuration, the following version numbers are generated:

  • AssemblyVersionAttribute -> (Never changed, used to derive other versions)
  • InformationalVersionAttribute -> NugetSemanticVersion (to make Semantic version 1.0 standard compatible version)
  • FileVersionAttribute -> HumanReadable2SlotTimestamp (to track compilation time)
  • ConfigurationAttribute -> HumanReadableBuildInfo (to track author, location, time, build configuration)

Built-in generators

The tool provides a number of prepared generators for typical uses and also a customizable generator for custom extensions, like source control integration, etc. The built-in generators are:

Skip

This generator instructs the tool that given attribute must NOT be generated. A typical use is when user is handling given attribute content manually themselves.

HumanReadable1SlotTimestamp

This generator is intended for storing the build date within standard 4-part version format. First 3 parts (major, minor, revision) are retained from assembly base version and the 4th is replaced by a UTC date encoded in 16-bit number (<65536). The used encoding is roughly equivalent to format "yMMdd". It retains easy readability and subsequently generated version numbers are non-decreasing.

Example: If assembly is built on March 29th 2015, with base version "1.2.3.0" then it would generate: "1.2.3.50329"

This is useful for use in FileVersionAttribute to allow quick overview from OS file properties window about both base version AND build date.

What will happen in 2017 when 70101 is no longer a valid 16-bit number? It will not break, wetween 2017-2019 the year part will be used as modulo 7.

HumanReadable2SlotTimestamp

This generator is similar to HumanReadable1SlotTimestamp but stores both build date and time. First 2 parts (major, minor) are retained from assembly base version, 3rd is replaced by a UTC date encoded in 16-bit number (<65536) and the 4th is replaced by UTC time part encoded in 16-bit number. The time part is encoded in human-readably format "HHmm".

Example: If assembly is built on March 29th 2015, 19:30, with base version "1.2.3.0" then it would generate: "1.2.50329.1930"

This is useful for use in FileVersionAttribute to allow quick overview from OS file properties window about both base version AND build time.

HumanReadableBuildInfoGenerator

This generator provides more information about where and how an assembly was built. It tracks build configuration (ex: Debug vs Release), UTC build time and the user/machine where build was triggered.

Example: "Debug (on UTC2015-03-29T13:59:56 by JohnSmith at BuildServer4)"

This is useful for tracking or verifying the origin of an assembly. A good choice for filling ConfigurationAttribute.

NugetSemanticVersionGenerator

This generator suits well for assemblies which follow semantic versioning standard and are packaged for reuse with NuGet. This generator generates different version info depending if it is built for pre-release or not. Normal builds generate standard 3-part version number using first 3 components from base version number. If assembly is built for pre-release (ex: debug mode), then build configuration and build time is added to pre-release component. Date component ensures that pre-release versions are properly ordered.

Example for base version "1.2.3.0":
Release build generates: "1.2.3"
Debug build generates: "1.2.3-Debug-20150311-0911"

Users can define which builds are prerelease by assining value to MSBuild property AssemblyVersioningIsPrerelease.

Custom generators

Users can build their own generators if the prepared ones do not suffice. They can enter a template for version information and the tool will recognize and replaces special tokens in curly braces with appropriate content during build. For dates and numbers standard .net format-strings can be applied to tokens.

Example: "Built on {Domain}{MachineName}, mode {BuildConfiguration}"
Example: "{Major}.{Now:yyyy}.{Now:MM}.{Now:dd}"

Supported tokens

Base version

Allows use of "base"-version components (from AssemblyVersionAttribute value read from project).

  • Major - 1st component of base version
  • Minor - 2nd component of base version
  • Revision - 3rd component of base version
  • Build - 4th component of base version

Build & environment information

  • UserName - name of user performing the build
  • MachineName - name of machine performing the build
  • Domain - domain name of user performing the build
  • BuildConfiguration - name of visual studio build configuration (ex: Debug, Release).

Time-related

  • Now, UtcNow - time of build
  • NowDateNumber, UtcNowDateNumber - human- readable date fitting into 16-bit number, in format XMMdd ** where X := ((year mod 10) mod 7); Ensuring date number can still fit into 16-bit number even after 2016. ** example: Jan 1st, 2010 => 00101 ** example: Sep 1st, 2015 => 50901 ** example: Dec 31st, 2016 => 61231 ** example: Jan 1st, 2017 => 00101 ** example: Jan 24st, 2021 => 10124
  • NowTimeNumber. UtcNowTimeNumber - time of build in format HHmm (ex: 2359), fits in 16-bit number slot in 4-part version.