Skip to content

XAML Update Version

Codeblack edited this page Mar 12, 2017 · 1 revision

Update-Version

Updates the version-attributes in source-code and nuspec-files. It supports the AssemblyVersionAttribute (which results in the assembly-version), AssemblyFileVersionAttribute (which results in the file-version) and the AssemblyInformationalAttribute (which results in the product-version).

This function first determines the base-version to use. This version may be specified using the Version-parameter. If it is not specified, the version is taken from the build-number. The version may be specified in a .Net (0.0.0.0) or SemVer format.

Next, the version is applied to the attributes. When a .NET version is used, the default behavior is to use the full version for all attributes. When a SemVer version is used, the default behavior is to use the full version only for the product-version attribute. Due to restrictions for the assembly- and file-version, only the first three segments are used with a 0 for the last segment (major.minor.patch.0).

To change the default behavior, specify a pattern for the corresponding pattern-parameter as described below.

Explicit version

In case the version is specified, the following rules apply:

  • If one of the following (uppercase!) symbols is used, it's corresponding value will be used instead.
    • YYYY: the current 4-digit year
    • YY: the current 2-digit year
    • M or MM: the number for the current month; MM only gives a leading 0 if not preceded by a dot ('.')
    • D or DD: the number for the current day; DD only gives a leading 0 if not preceded by a dot ('.')
    • J: the current date in "Julian" 5-digit format (YYDDD where YY is the year and DDD is the number of the day within the year e.g., 14075 is March 16, 2011 – there are leading 0’s for the day)
    • B or BB: the current build-revision number, which is automatically incremented by TFS when the rest of the build-number is the same; BB only gives a leading 0 if not preceded by a dot ('.') or when using SemVer
  • If any other character a number is used in any position in the version pattern, then that character/number is used as is; to use a character that is also a symbol (e.g. b in beta), use lowercase to prevent it from being replaced

Note: using the B-symbol requires that the "Build Number Format" ends with "$(Rev:.r)", which is the case when creating a new build-definition.

Examples:

  • "YYYY.MM.DD.B": if you queued up the 2nd build of the day on November 8, 2014, the version would be: "2014.11.8.2"
  • "1.0.J.B": if you queued up the 2nd build of the day on November 8, 2014 the version would be: "1.0.14312.2"
  • "2.1.4-ci+J.BB": if you queued up the 2nd build of the day on November 8, 2014 the version would be: "2.1.4-ci+14312.02"

Version in the build-number

In case the version is not specified, the version is retrieved from the build-number, by looking for a .Net (0.0.0.0) or SemVer pattern. Read this MSDN article to learn about how to specify the build-number-format.

Examples:

  • $(BuildDefinitionName)_$(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r): will, for the 2nd build on November 8, 2014, result in build-number "HelloWorld_2014.11.8.2"; this version would then be "2014.11.8.2"
  • $(BuildDefinitionName)_1.0.$(Year:yy)$(DayOfYear)$(Rev:.r): will, for the 2nd build on November 8, 2014, result in build-number "HelloWorld_1.0.14312.2"; this version would then be "1.0.14312.2"
  • $(BuildDefinitionName)_2.1.4-ci+$(Year:yy)$(DayOfYear)$(Rev:.r): will, for the 2nd build on November 8, 2014, result in build-number "HelloWorld_2.1.4-ci+14312.02"; this version would then be "2.1.4-ci+14312.02"
  • $(BuildDefinitionName)_$(Date:yyyy-MM-dd)_2.1.4-ci+$(Year:yy)$(DayOfYear)$(Rev:.r): will, for the 2nd build on November 8, 2014, result in build-number "HelloWorld_2014-11-08_2.1.4-ci+14312.02"; this version would also be "2.1.4-ci+14312.02", the same as the previous example

Version patterns

The version pattern for each attribute may be specified using the corresponding parameter. A version pattern may be specified in the same way as the explicit version parameter, by using symbols, characters and numbers.

Additionally, placeholders ('#') may be used, where the actual value is taken from the base-version in the order the placeholders are specified. So in case of a base-version "1.2.3.4" and a pattern "#.#.0.0, the resulting version is "1.2.0.0". But be careful, because in case of a base-version "1.2.3.4" and a pattern "#.0.#.0, the resulting version is "1.0.2.0"

Parameters

SourcesDirectory

Specifies the root-directory containing the source-files.

AssemblyVersionFilePattern

Specifies the pattern to use for finding source-files containing the version-attributes. Default is "AssemblyInfo.*".

BuildNumber

Specifies the build-number from which to take the version-number. This parameter is ignored if the Version parameter is provided.

Version

Specifies the version to use. May contain the following tokens :'YYYY', 'YY', 'M', 'MM', 'D'. 'DD', 'J', 'B' and 'BB'.

AssemblyVersionPattern

Specifies the version, or pattern, for the assembly-version. Depending on the provided version (either through the Version or BuildNumber parameters) the default is '#.#.#.#' (.NET) or '#.#.#.0' (SemVer).

FileVersionPattern

Specifies the version, or pattern, for the assembly-file-version. Depending on the provided version (either through the Version or BuildNumber parameters) the default is '#.#.#.#' (.NET) or '#.#.#.0' (SemVer).

ProductVersionPattern

Specifies the version, or pattern, for the assembly-informational-version. Depending on the provided version (either through the Version or BuildNumber parameters) the default is '#.#.#.#' (.NET) or '#.#.###' (SemVer).

PackageVersionPattern

Specifies the version, or pattern, for the nuget-packages. Depending on the provided version (either through the Version or BuildNumber parameters) the default is '#.#.#.#' (.NET) or '#.#.##' (SemVer).

WhatIf

Specifies that no changes should be made.

Clone this wiki locally