To assign the build number as the assembly version, PowerShell script available here can be used. Let’s see how to set this up for TFS builds step by step.
First, a small console application created below as the sample.
Code segment written to output the assembly version.
Setup a build in Visual Studio Team Services to build the application. Build number is set to represent version 4.1.3.X (the X is the build number for version 4.1.3). This can be set to match regex pattern "\d+\.\d+\.\d+\.\d+".
Set the repository path
This builds successfully and the build output contains the .exe.
Next download the “ApplyVersionToAssemblies.ps1” from here. Download link can be found in this page.
Add the script to the Team Project and check in.
Add new build step to execute PowerShell script.
Move the added step as the first step.
Set the script.
When build script downloaded from github this error occurs due to incorrect environment variable. The script is developed to work with TFS 2013 XAML template builds. The scriptceript should be updated to “$Env:BUILD_SOURCESDIRECTORY”, “$Env:BUILD_BUILDNUMBER”, instead of “$Env:TF_BUILD_SOURCESDIRECTORY”, “$Env:TF_BUILD_BUILDNUMBER”. Remove the “-not $Env:TF_BUILD” condition.
The above changes make the compatible to run with new TFS build. The assemblies now get updated with the build number as version number.