Versioning .Net assemblies using TFS/VSTS Build.BuildID

The semantic versioning used in all of our TFS/VSTS CI builds uses the predefined variable Build.BuildID for the buildnumber portion of major.minor.revision.buildnumber. The build id is used so we have traceability when troubleshooting. We can easily search for the build and see the associated changes. Major.minor.revision is set in a variable group so it can be shared and updated in one place, across build definitions.

I set the version in the AssemblyInfo.cs file of all projects before compilation to version our assemblies. This is done via a simple PowerShell script:

When our build id reached 65535, Roslyn (.NET Compiler Platform) error-ed when building our projects:

AssemblyInfo.cs: Error CS7034: The specified version string does not conform to the required format - major[.minor[.build[.revision]]]

It turns out that the compiler uses the data type “unsigned __int16” (i.e. unsigned 2-byte int) which has a range from 0 to 65,535.

As a workaround, I modified the script above to remove the first digit from the build id $env:Build_BuildID.Substring(1). VSTS support said it would not be possible to reset the build id’s…

Has anybody out there come up with a better solution?

2 thoughts on “Versioning .Net assemblies using TFS/VSTS Build.BuildID

  1. Hi. I haven’t used it yet, but maybe https://github.com/AArnott/Nerdbank.GitVersioning would be helpful? It’s on my backlog to move to using it.

    If you’re anything like me you’ll need to try to ignore the “Nerdbank” namespace. Andrew Arnott actually works at Microsoft, and he definitely knows what he’s doing. I don’t know why he chose that namespace, but who knows, there might be some historical reason it’s still there.

    Anyway, it definitely would satisfy your stated requirement: “The build id is used so we have traceability when troubleshooting. We can easily search for the build and see the associated changes”.

    HTH

    1. Yann,

      Versioning based on Git commit is an excellent idea! Going to take it for a test drive. I really appreciate your help. Thanks for chiming in.

      Marcus

Leave a Reply

Your email address will not be published. Required fields are marked *