Use PowerShell and Build vNext to Version Assembly
Check out this post and learn how to version Assembly using PowerShell and Build vNext.
Join the DZone community and get the full member experience.Join For Free
in an old blog post, i explained how to version assembly during tfs 2013 build with powershell scripts . the goal is modifying assemblyinfo.cs and assemblyinfo.vb with powershell in a tfs 2013 build for a project based on tfvc. if you are interested in git, i’ve another post on the subject .
now that the build system is changed in visual studio team services and in tfs 2015, people asked me to update scripts to work with the new build system . it turns out that the work needed to update the scripts is only one line of code, because an environment variable is changed between the two build systems, but all the rest remains equal.
if you use powershell scripts to customize the build, you are less dependant on build infrastructure and you have an easy path on moving to new build systems.
you can download a zip with the script from this address , and the usage is straightforward . just check-in the scripts under a directory of your project, or in a common directory in tfvc. once you’ve checked in the file, you can simply add a powershell script task before the actual build .
figure 1: add powershell script before the build stage
then i simply specify where the script is located in my source control and specify the list of arguments it needs.
figure 2: configure the script to run
this script needs a bunch of parameters to run:
-srcpath $(build.sourcesdirectory)\src -assemblyversion 188.8.131.52 -fileassemblyversion 2.5.j.b
version number has a special syntax where j is substituted with date expressed with 5 digits: first 2 represents the year 2016 is 16, while the other three digits represent the progressive number of days in the year. the other special char is b that is substituted with build progressive number. if you remember the default build number in tfs / vsts ends with a dot followed by the daily incremental number for the build.
there are no special operations to do in your build. here is the output.
figure 3: output of the build
selecting the powershell task, you can verify (2) that the script correctly determines version number as 2.5.16023.4. this is the fourth build of 23 january 2016 . in point 3, you can see that the script simply changed various assemblyinfo.cs and assemblyinfo.vb to update the number before the build.
thanks to powershell, i was able to fully reuse a script prepared for the old build system in the new system with very little work.
Published at DZone with permission of Ricci Gian Maria, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.