Rory Primrose

Learn from my mistakes, you don't have time to make them yourself

View project on GitHub

AssemblyVersion regular expression

It seems that I keep having to come up with a regular expression that validates and parses a version string. I often use this for customising TFS build workflows for extracting and using application version information.

The AssemblyVersionAttribute appears to have the following rules:

  • Major version is required
  • Minor version is optional and will default to 0 if not specified
  • Minor version cannot be *
  • Build and Revision versions are optional and may be *
  • Revision number cannot be specified if the build number is *

The following is the regular expression that covers all these rules.

# Major version must exist
  # Minor only supports numbers

      # Build can be *
      # or a number

        # with optional Revision that may be * or numeric
  )? # Build.Revision is optional
)?$ # Minor.Build.Revision is optional

The following is the same expression without the comments and whitespace.



Written on November 7, 2011