Customize Team Build 2010 – Part 5: Increase AssemblyVersion

by Ewald Hofman 13. May 2010 08:33

In the series the following parts have been published

  1. Part 1: Introduction
  2. Part 2: Add arguments and variables
  3. Part 3: Use more complex arguments
  4. Part 4: Create your own activity
  5. Part 5: Increase AssemblyVersion
  6. Part 6: Use custom type for an argument
  7. Part 7: How is the custom assembly found
  8. Part 8: Send information to the build log
  9. Part 9: Impersonate activities (run under other credentials)
  10. Part 10: Include Version Number in the Build Number
  11. Part 11: Speed up opening my build process template
  12. Part 12: How to debug my custom activities
  13. Part 13: Get control over the Build Output
  14. Part 14: Execute a PowerShell script
  15. Part 15: Fail a build based on the exit code of a console application
  16. 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.

  1. Open the solution that is created in the following post: Customize Team Build 2010 – Part 4: Create your own activity.

    IncreaseAssemblyVersion
  2. Add in the Activities folder a new class called “IncreaseAssemblyVersion”
  3. In this class we add the arguments AssemblyInfoFileMask and SourcesDirectory
     
    image
  4. Then we override the Execute method, which increases the build number of the version (which is the 3rd number) in all the AssemblyInfo files. 

    image 

    Checkout
  5. Add in the Activities folder a new class called “Checkout”
  6. In this class we add the arguments AssemblyInfoFileMask and Workspace
      
    image
  7. Then we override the Execute method, which checks all files out that are in the scope of the defined workspace in the build definition. 

    image 

    Checkin
  8. Add in the Activities folder a new class called “Checkin”
  9. In this class we add the argument Workspace
      
    image
  10. 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 

    image
  11. Now we add the new activity to the Build Process Template. Open the CustomTemplate.xaml in the Template project.
  12. When you open the toolbox, you see all the activities that are in the BuildTasks assembly, including the Checkin, Checkout and the IncreaseAssemblyVersion activities

     image
  13. 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. 

      image
  14. When you look at the properties for the Checkout activity, you have to set the values for two arguments 

    image
  15. 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

    image
  16. Open the Metadata and create a new entry

     image
  17. 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
  18. Save the CustomTemplate.xaml and check in the file.
  19. 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.

    image
  20. 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.

Tags:

Team Build | VSTS 2010

Comments

5/18/2010 7:58:40 AM #

Purple.Kate

This series about customising the Team Build 2010 has been really helpful.

Thank you,

Kate

Purple.Kate United Kingdom |

5/19/2010 12:24:51 PM #

trackback

Understanding the new style Team Build under TFS 2010

I found this series of posts about customising Team Build 2010 from Ewald Hofman: http://www.ewaldhofman

Purple Kate |

5/26/2010 4:44:13 AM #

Xavier Wolfs

This was a great series of posts, which helped me along with working with Team Build 2010.

Thanks a bunch

Xavier Wolfs Netherlands |

6/10/2010 4:05:40 AM #

Patrick

Hi, this article is great!
I have one problem with the setting values, in point 17. you have a table with the values for the activites:

Checkout/Checkin: In Workspace set Workspace ?? I have no variable for this or what must i set here. Can i give all projects for the solution or a specific one?

IncreaseAssemblyVersion: The same for SourcesDirectory, which must i set here?

Hope you can help me.

Patrick Germany |

6/10/2010 5:07:29 AM #

Ewald Hofman

There is a variable Workspace and SourceDirectory in the Build Process Template that is delivered with TFS. When you start typing, you should see this variable come up in the intellisense.

Ewald Hofman Netherlands |

6/10/2010 5:24:03 AM #

Patrick

Hi, i solved my problem, it was that I have put the sequence after the "Get the Build" and not after the "Get Workspace".

Patrick Germany |

7/15/2010 7:27:19 AM #

Bob Hardister

Great post! I went ahead and enhanced the code to use the build increment number as the build number in the assembly. I also changed it to use the primary.secondary.maintenace.build format. It works great!

Bob Hardister United States |

10/15/2010 9:13:10 PM #

Ryan

Excellent work here Ewald! There are some fantastic posts across the site and this is certainly one of them!Laughing

Ryan United Kingdom |

11/9/2010 5:32:32 AM #

trackback

Part 14: Execute a PowerShell script

Part 14: Execute a PowerShell script

Ewald Hofman |

11/11/2010 1:36:35 AM #

Marcel Malik

Great post!

Sometimes I have the error "TF10141: No files checked in: resolve the conflicts and try again.".
Have you an idea, why?

Thank you,
Marcel

Marcel Malik Germany |

11/25/2010 5:54:23 AM #

Ewald Hofman

The only thing I can think of are two builds running in parallel (both builds increase the version to the same version)

Ewald Hofman Netherlands |

5/22/2011 9:34:02 PM #

Lance Roberts

Actually what happens is two people check something into the same branch before the build kicks off - it gets the first checkin, increases the assembly version, and checks in the increase AFTER the second person's checkin.  When it comes to build their checkin it gets the old assembly version numbers out and tries to increase them again to the same value - which is of course a conflict.

Lance Roberts New Zealand |

2/23/2011 9:54:06 AM #

Eric

Did you ever resolve this issue? I am seeing the same thing when 2 different build definitions are queued at the same time.

Eric United States |

1/14/2011 2:32:38 AM #

Scott

Hi,

On the checkin.cs activity is there any way to bypass checkin policy? I need to do this as the checkin fails do to gated builds which are in place.

Many Thanks,

Scott.

Scott United Kingdom |

1/31/2011 11:11:37 AM #

Srikanth Srinivasan

After check out I get the following error in the log:

Access to the path 'c:\builds\KrisA\Abc\Sources\BuildProcess\BuildTasks\Properties\AssemblyInfo.cs' is denied.

Srikanth Srinivasan United States |

2/4/2011 8:13:54 AM #

Ewald Hofman

Are you sure that you have checked out the file in the correct workspace? Checking a file out is removing the readonly attribute from the file.

Ewald Hofman Netherlands |

2/1/2011 2:21:15 PM #

Srikanth Srinivasan

Great intro to XAML ! Thanks.

Srikanth Srinivasan United States |

3/9/2011 8:09:09 AM #

gbrout

Thanks for all your articles, they are really great and help me so much.

But I just want to make a little remark : I'm not totally agree with Checkin/Checkout operation during a build.
In some of my project we have rule that launch a build on every Checkin and this can be cause some mistake...
but for the moment I don't find another solution!

gbrout France |

5/24/2011 4:46:45 PM #

Lance Roberts

Personally I prefer not to checkin too.  The better solution is to put the latest commit revision number in to the assembly build version if it is suitable - as this helps you trace what is in a particular build also and you don't need to check it in to know what it is for a particular build either.

Lance Roberts New Zealand |

3/9/2011 9:41:01 PM #

Satya Srikanth Mantha

I agree with gbrout.. in scenarios where there are multiple build definition defined on a project for triggers like gated checkins .. the checkout and checkins on version assembly files can trigger these builds..(This is by experience which we observed..)

@gbrout: We did a workaround for it, instead of checking out a file we cleared the readonly flag programatically and increment the assembly version and then made the file readonly again...this has almost same affect as checkout and checkin.. at least during build process.

Also there is a way to supress continuous integration build triggers a simple comment during checkin does it ("****NO_CI****") a specified by Ewald, however is there a way to supress gated Checkin builds?

Satya Srikanth Mantha India |

3/10/2011 12:53:48 AM #

gbrout

Thanks for the info, I have implemented your solution by removing the readonly attributes (myFile.Attributes -= FileAttributes.ReadOnly;) and this works great.

gbrout France |

3/10/2011 2:29:32 AM #

Scott

Hi,

I ended up using InvokeProcess and TF.exe to do the check-in and bypass gated checkin policy. Let me know if you want more info on this.

Cheers.

Scott United Kingdom |

3/10/2011 9:09:07 PM #

pingback

Pingback from community.dynamics.com

Incrementing Assembly Version in TFS Builds and its affect over Other Build Definitions - Satya Srikant Mantha - AX Technical Blogs - Microsoft Dynamics Community

community.dynamics.com |

3/17/2011 8:08:14 AM #

Tampaite

Thanks for making the BuildProcess.zip file available.

I downloaded the file but am unable to open the CustomTemplate.xml...

Getting the below error

Workflow Designer encountered problems with your document.

Please check the document for invalid content, namespaces, references or reference loops

System.Xaml.XamlException: 'The type ‘InArgument(bc:Credential)’ of property ‘Credentials’ could not be resolved.' Line number '23' and line position '36'.
   at System.Activities.XamlIntegration.DynamicActivityXamlReader.BufferedPropertyList.ActivityPropertyHolder..ctor(DynamicActivityXamlReader parent, XamlReader reader)
   at System.Activities.XamlIntegration.DynamicActivityXamlReader.BufferedPropertyList.BufferDefinitions(DynamicActivityXamlReader parent)
   at System.Activities.XamlIntegration.DynamicActivityXamlReader.ProcessCurrentNode()
   at System.Activities.XamlIntegration.DynamicActivityXamlReader.Read()
   at System.Xaml.XamlServices.Transform(XamlReader xamlReader, XamlWriter xamlWriter, Boolean closeWriter)
   at System.Activities.Presentation.WorkflowDesigner.DeserializeString(String text, Boolean errorTolerant, IList`1& loadErrors)
   at System.Activities.Presentation.WorkflowDesigner.DeserializeString(String text, IList`1& loadErrors)
   at System.Activities.Presentation.WorkflowDesigner.Load()

Tampaite United States |

5/25/2011 10:44:14 PM #

Nalaka

I downloaded the file but unable to open the CustomTemplate.xml...
I got the following error

Workflow Designer encountered problems with your document

Please check the document for invalid content, namespaces, references or reference loops.

'The type 'InArgument(bc:credential)' of property 'Credentials' could not be resolved.'Line number '23' and line position '36.

Nalaka Sri Lanka |

5/31/2011 8:22:03 AM #

trackback

Ewald’s posts on TFS Build 2010

Ewald Hofman , an ALM MVP, has written a great series of blog posts on Team Build in Team Foundation Server 2010.  The 2010 release introduces Windows Workflow as the overall orchestrator of the build process.  Ewald walks you through quite a few topics related to this and the other new features.  Check it out! 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 Technorati Tags: tfs 2010 , team build , windows workflow

Buck Hodges |

8/5/2011 12:22:00 PM #

pingback

Pingback from programmersgoodies.com

MSBuild: Modify Solution File using FileUpdate Task or Similar Task - Programmers Goodies

programmersgoodies.com |

5/16/2012 12:42:33 AM #

pingback

Pingback from wiert.me

Some research links on “change assemblyversion during checkin ccnet”via Google Search” « The Wiert Corner – irregular stream of Wiert stuff

wiert.me |

5/24/2012 3:29:03 PM #

pingback

Pingback from dkphp.com

How to checkin the output of a project/solution (dll) post a successful build in TFS2010 | PHP Developer Resource

dkphp.com |

5/25/2012 7:13:36 AM #

pingback

Pingback from leandroprado.com.br

Alterando a versão do Assembly Info com TFS Build | @{ new Blog("Leandro Prado"); }

leandroprado.com.br |

6/3/2012 6:55:20 PM #

pingback

Pingback from dkphp.com

Checkout files in Teambuild (TFS2010) | PHP Developer Resource

dkphp.com |

5/16/2013 2:04:37 AM #

pingback

Pingback from blog.developpez.com

Benjamin Devuyst

blog.developpez.com |

11/6/2013 12:49:23 PM #

pingback

Pingback from queryby.com

Does TFS 2010 Team Build suppress checkins during the build, even if part of the build?QueryBy | QueryBy, ejjuit, query, query by, queryby.com, android doubt, ios question, sql query, sqlite query, nodejsquery, dns query, update query, insert query, kony, mobilesecurity, postquery, queryposts.com, sapquery, jquery, mobilequery,gsm query, cdmaquery, phonegap, appcelerator

queryby.com |

11/6/2013 12:49:28 PM #

pingback

Pingback from copyquery.com

Does TFS 2010 Team Build suppress checkins during the build, even if part of the build?CopyQuery CopyQuery | Question & Answer Tool for your Technical Queries,CopyQuery, ejjuit, query, copyquery, copyquery.com, android doubt, ios question, sql query, sqlite query, nodejsquery, dns query, update query, insert query, kony, mobilesecurity, postquery, queryposts.com, sapquery, jquery, mobilequery,gsm query, cdmaquery, phonegap, appcelerator

copyquery.com |

11/15/2013 1:36:05 PM #

pingback

Pingback from jptab.com

Is it possible to automatically convert Visual Studio TODO comment tasks into Team Foundation work items? | Jptab

jptab.com |

Comments are closed

Powered by BlogEngine.NET 1.6.1.0
Theme by Mads Kristensen


ClusterMap

Statistics

Statistics created at 09 Sep 2009

121 posts
493 comments
328 raters
1949127 visit (1042 per day)
10 users online

Recent comments

Comment RSS