Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Use PowerShell and Build vNext to Version Assembly

DZone's Guide to

Use PowerShell and Build vNext to Version Assembly

Check out this post and learn how to version Assembly using PowerShell and Build vNext.

· Web Dev Zone
Free Resource

Prove impact and reduce risk when rolling out new features. Optimizely Full Stack helps you experiment in any application.

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.

image_thumb[2]














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.

image_thumb[5]






Figure 2: Configure the script to run

This script needs a bunch of parameters to run:

-srcPath $(Build.SourcesDirectory)\src -assemblyVersion 2.5.0.0 -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.

image_thumb[8]

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.

With SDKs for all major client and server side platforms, you can experiment on any platform with Optimizely Full Stack.

Topics:
tfs ,powershell ,build ,development

Published at DZone with permission of Ricci Gian Maria, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}