by Ewald Hofman
13. May 2010 08:33
In the series the following parts have been published
- Part 1: Introduction
- Part 2: Add arguments and variables
- Part 3: Use more complex arguments
- Part 4: Create your own activity
- Part 5: Increase AssemblyVersion
- Part 6: Use custom type for an argument
- Part 7: How is the custom assembly found
- Part 8: Send information to the build log
- Part 9: Impersonate activities (run under other credentials)
- Part 10: Include Version Number in the Build Number
- Part 11: Speed up opening my build process template
- Part 12: How to debug my custom activities
- Part 13: Get control over the Build Output
- Part 14: Execute a PowerShell script
- Part 15: Fail a build based on the exit code of a console application
- Part 16: Specify the relative reference path
In this post I will show you how you can create an activity to increase the version in the AssemblyInfo file. The solution is pretty simple and could be the base for your own implementation if you want to have another approach.
The solution uses the version number that is stored in the AssemblyInfo file in Source Control. The advantage is that it is the simplest implementation possible, but for every changeset you will get an additional changeset with the change on the AssemblyInfo which ‘pollutes’ the History of your code base. Another approach could be is to store the latest version number in an external system (like a file or database), or to use a generated version number (such as the date: <year>.<month>.<day>.0).
At the end of the post, the three classes, that are required for the solution, are attached for your convenience.
- Open the solution that is created in the following post: Customize Team Build 2010 – Part 4: Create your own activity.
IncreaseAssemblyVersion
- Add in the Activities folder a new class called “IncreaseAssemblyVersion”
- In this class we add the arguments AssemblyInfoFileMask and SourcesDirectory
- Then we override the Execute method, which increases the build number of the version (which is the 3rd number) in all the AssemblyInfo files.
Checkout
- Add in the Activities folder a new class called “Checkout”
- In this class we add the arguments AssemblyInfoFileMask and Workspace
- Then we override the Execute method, which checks all files out that are in the scope of the defined workspace in the build definition.
Checkin
- Add in the Activities folder a new class called “Checkin”
- In this class we add the argument Workspace
- Then we override the Execute method, which checks all pending changes in the workspace in. These pending changes are all the files that are changed by the IncreaseAssemblyVersion activity
- Now we add the new activity to the Build Process Template. Open the CustomTemplate.xaml in the Template project.
- When you open the toolbox, you see all the activities that are in the BuildTasks assembly, including the Checkin, Checkout and the IncreaseAssemblyVersion activities
- Now navigate in the CustomTemplate workflow to the “Get Workspace” activity (which is halfway in the workflow). From the Control Flow tab in the Toolbox drop the Sequence activity below the Get Workspace activity. Then add the Checkout, IncreaseAssemblyVersion and Checkin activity in the Sequence.
- When you look at the properties for the Checkout activity, you have to set the values for two arguments
- For the AssemblyInfoFileMask you can either specify an hard-coded value in the template (so every build that uses the template uses the same mask), or you can create an argument (so every build can configure its own mask) and use that argument as the value. I choose to use a argument. To do this, add an AssemblyInfoFileMask argument to the Build Process Template
- Open the Metadata and create a new entry
- Now that argument is created, it is easy to setup the workflow. You can see the values in the following table.
Activity |
Property |
Value |
Checkout |
AssemblyInfoFileMask |
AssemblyInfoFileMask |
|
Workspace |
Workspace |
IncreaseAssemblyVersion |
AssemblyInfoFileMask |
AssemblyInfoFileMask |
|
SourcesDirectory |
SourcesDirectory |
Checkin |
Workspace |
Workspace |
- Save the CustomTemplate.xaml and check in the file.
- Now Edit the build definition that makes use of this Build Process Template and go to the Process tab. Since we have defined a default value for the argument, it is prefilled. Change it when applicable.
- Now queue your build and you will get an incremental unique version number. You can tweak it to your own needs.
You can download the full solution at BuildProcess.zip. It will include the sources of every part and will continue to evolve.