Whenever a new .NET assembly project is created in Visual Studio, a file named AssemblyInfo is created that contains attributes used to define the version of the assembly during compilation. Using assembly versions effectively enables various team members to identify deployed assemblies and helps troubleshoot problems that may occur in a particular environment (e.g. Development, Test, or Production).
When building the solution, there are two version numbers that need to be considered: the file version number and the .NET assembly version number. As part of the best practices, the AssemblyFileVersion attribute should be incremented automatically as part of the build process. It is therefore intended to uniquely identify a build. The AssemblyVersion attribute is the version that .NET uses when linking assemblies. In this blog post, we’ll learn how to use the build process to auto specify the AssemblyFileVersion and AssemblyInformationalVersion.
First, we need to create and check a custom written PowerShell script into our codebase:
Once its checked in, we need to modify the build definition to include a PowerShell task and provide the script path and arguments as shown below:
Do note that above task should come before you start building solution using msbuild or visual studio task. Also note that in the arguments, we have mentioned 1.0.0. It will be used to identify the AssemblyVersion attribute.
Now, we need to go ahead and start the build. During build we can see output like below for PowerShell task added:
2017-09-04T04:16:08.5335455Z VERBOSE: Executing Update-AssemblyInfoVersionFiles in path d:\a\1\s for product version Version 1.0.0 2017-09-04T04:16:08.8305461Z VERBOSE: Transformed Assembly Version is 1.0.0 2017-09-04T04:16:08.8305461Z VERBOSE: Transformed Assembly File Version is 188.8.131.52 2017-09-04T04:16:08.8315482Z VERBOSE: Transformed Assembly Informational Version is 1.0.0 2017-09-04T04:16:08.8905460Z 184.108.40.206 2017-09-04T04:16:08.9095447Z ##[section]Finishing: PowerShell Script
Now if we download artifacts and see the properties of assembly generated, we would be able to see the correct metadata.
For more information on various assembly versioning attributes, please refer this link on stackoverflow