The AssemblyInfo activity allows you to get and set the properties in one or more AssemblyInfo.cs files.This activity should be used prior to building the projects in a build workflow, it edits the files on the build agent PC. In this example we aim to show the the basic steps that are required to get the activity integrated into a build.

Before you can make use of any of the TFS community build activities you have to make sure they are available for the build system and on your development PC. Instructions for this process can be found in the ALM Rangers build guide or in the StyleCop page of this wiki. This page assumes the AssemblyInfo activity is available in the developers build process workflow toolbox.

The following workflow should be built at the end of the ‘Initialize Workspace’ sequence


image

Step 1 – Getting the files

The first step is find the Get Workspace activity in your build process, this is where the files are pulled from the TFS server to the local build agents workspace. After this activity add a FindMachingFiles activity (from the Team Foundation Build Activities tab in the toolbox). In the workflow above it has the display DisplayName of “Find the AssemblyInfo files”. As the name suggests this activity is used to find all the assemblyinfo.cs files in the build we will be editing.

The result of this find is stored in a workflow variable AssemblyInfoFiles. This should to be created with a type of IEnumerable<string>; it’s scope, in the default workflow, was set to Initialize workspace. Once the variable was created the activities output can be assigned to it

image

Note This sample only looks for .CS files, you can have a build that looks for assemblyinfo.* hence picking up .CS, .VB and .FS version within the same solution. In this case the edits would be applied to all assemblyinfo files that match the find files criteria

Step 2 – A bit of logging

It is useful to list the files that will be updated in the build log. To do this add a ForEach activity (from control flow tab in toolbox) that returns each file name (string) in the FileToVersion collection variable and logs them via a WriteBuildMessage (from the Team Foundation Build Activities tab in the toolbox). This is set to High importance to make sure it appears in the log.

image

Step 3 – The Actual Editing

Next add the AssemblyInfo activity (from whichever tab it was added to in toolbox). As a minimum you need to set the Files property to the list of AssemblyInfo files previously found and at least one other property you wish to reset. You can of course update as many as you wish with a single instance of the activity.

image

The following is a list of the properties available. Note that many allow use the tokens to allow the updating of current values

Property Direction Comment
Files InArgument<IEnumerable<string>> [Required] Sets the AssemblyInfo files to update
AssemblyVersion InArgument<string>

Setting the value to null will disable updating this attribute.
The following tokens are supported

  • $(current)
  • $(increment)
  • $(date:<format>)

e.g.  “$(current) .$(current).$(increment).$(date:yyyy)“

AssemblyFileVersion InArgument<string>

Setting the value to null will disable updating this attribute.
The following tokens are supported

  • $(current)
  • $(increment)
  • $(date:<format>)
AssemblyInformationalVersion InArgument<string>

Setting the value to null will disable updating this attribute.
The following tokens are supported

  • $(version)
  • $(fileversion)
  • $(date:<format>)
AssemblyCompany InArgument<string>

Setting the value to null will disable updating this attribute.
The following tokens are supported

  • $(version)
  • $(fileversion)
  • $(date:<format>)
AssemblyConfiguration InArgument<string>

Setting the value to null will disable updating this attribute.
The following tokens are supported

  • $(version)
  • $(fileversion)
  • $(date:<format>)
AssemblyCopyright InArgument<string>

Setting the value to null will disable updating this attribute.
The following tokens are supported

  • $(version)
  • $(fileversion)
  • $(date:<format>)
AssemblyCulture InArgument<string>

Setting the value to null will disable updating this attribute

AssemblyDelaySign InArgument<bool?>

Setting the value to null will disable updating this attribute

Set to true to mark the assembly for delay signing.
AssemblyDescription InArgument<string>

Setting the value to null will disable updating this attribute.
The following tokens are supported

  • $(version)
  • $(fileversion)
  • $(date:<format>)
Guid InArgument<System.Guid?> Sets the assembly GUID
Setting the value to null will disable updating this attribute.
AssemblyKeyFile InArgument<string> Sets the key file to use to sign the assembly
Setting the value to null will disable updating this attribute.
AssemblyKeyName InArgument<string> Sets the name of a key container within the CSP containing the key pair used to generate a strong name
Setting the value to null will disable updating this attribute
AssemblyProduct InArgument<string>

Setting the value to null will disable updating this attribute.
The following tokens are supported

  • $(version)
  • $(fileversion)
  • $(date:<format>)
AssemblyTitle InArgument<string>

Setting the value to null will disable updating this attribute.
The following tokens are supported

  • $(version)
  • $(fileversion)
  • $(date:<format>)
AssemblyTrademark InArgument<string>

Setting the value to null will disable updating this attribute.
The following tokens are supported

  • $(version)
  • $(fileversion)
  • $(date:<format>)
CLSCompliant InArgument<bool?> Set to true to mark the assembly CLS compliant.

Setting the value to null will disable updating this attribute.

ComVisible InArgument<bool?> Set to true to mark the assembly ComVisible .

Setting the value to null will disable updating this

MaxAssemblyVersion OutArgument<Version> Gets the max computed version
MaxAssemblyFileVersion OutArgument<Version> Gets the max computed version
MaxAssemblyInformationalVersion OutArgument<string> Gets the max computed version
AssemblyVersions OutArgument<IEnumerable<Version>> Gets the updated assembly versions
AssemblyFileVersions OutArgument<IEnumerable<Version>> Gets the updated assembly versions
AssemblyInformationalVersions OutArgument<IEnumerable<string>> Gets the updated assembly versions


The following tokens are supported for replacement (all tokens are not supported by every property, see properties comments for the list of supported tokens):

The general usage for tokens is as follows

  • To build the [Major], [Minor], [Release] or [Build] values in a version number e.g. AssemblyVersion = “$(current) .$(current).$(increment).$(date:yyyy)“
  • To build a string based property e.g. AssemblyTitle="The version is $(version) $(date:yyyy)"

Token Description
$(current) Uses the current value i.e the current integer value for one of the[Major], [Minor], [Release] or [Build] values in a version number
$(increment) Uses an incremented value i.e the current integer value plus one for one of the[Major], [Minor], [Release] or [Build] values in a version number
$(date:<format>) Uses the current date formatted with the specified standard date formatting string for one of the[Major], [Minor], [Release] or [Build] values in a version number, note the result must be an integer if being used to build a version number, but can be any string format if being used in a string based property
$(version) The updated AssemblyVersion value
$(fileversion) The updated AssemblyFileVersion value

Running the build

Save the edited build process template and create a build using it. if you chose to expose any of the new activity properties out via a build arguments you should set these prior to running the build. Once this is done the build can be run and you should be able to see your changes to the assembly properties

When the build runs it should show the generated version number in the log and the built assemblies should have the version details expected.

image

Last edited Mar 27, 2012 at 1:01 PM by rfennell, version 2

Comments

fabhar Jun 3, 2014 at 7:37 AM 
Hi, there is a BUG in this activity.

Once the AssemblyInfo finishes updating the file, it will add additional character (i suspect a newline character, either Line Feed (\n) or Carriage Return (\r)) since the caret in file that have been updated goes to next line, and not the last character in the file. This is potentially dangerous, especially if your next activity going to stream the file content and grab data from the stream by assuming specific numbers of characters to read.

Can someone have a look on this? Or should i file an Issue for tracking? Thanks!

WinterCloud Jul 9, 2013 at 4:35 PM 
Anyone has an idea how to avoid "Invalid L-value expression error"? If using Variable, how to set variable value to "$(current).$(current).$(increment).$(increment)" ? Thanks.

DrDelete Jan 7, 2013 at 2:33 PM 
The Invalid L-value expression error can be fixed by using variables instead of direct value.

WiredWiz Dec 18, 2012 at 7:44 PM 
I have also noticed that after I drop the assemblyinfo activity on the default VS2012 template I'm editing, I get tons of validation errors all throughout my template. These errors then persist even if I remove the AssemblyInfo activity. I'm beginning to think TFS's build server is too much of a pain in the butt to make it worth using.

WiredWiz Dec 18, 2012 at 3:01 PM 
I am also getting the error "Invalid L-value expression" when I use the custom version number expression values.

bradwist Dec 13, 2012 at 8:28 PM 
i have tried entering values for AssemblyVersion and AssemblyFileVersion. Entering the following "$(current).$(current).$(current).$(increment)", as well as variations of that entry, including examples above, just give a error in the expression editor. Error is:

Compiler error(s) encounter processing expression ""$(current).$(current).$(current).$(increment)"". Invalid L-value expression.

Still working to identifying the root cause of this.

idenys Jul 20, 2012 at 6:03 PM 
I am getting an error:
Error: Current value for attribute 'AssemblyFileVersion' is not in a correct version format.. Stack Trace: at TfsBuildExtensions.Activities.Framework.AssemblyInfo.UpdateVersion(String attributeName, String format, OutArgument`1 maxVersion) in D:\Projects\teambuild2010contrib\CustomActivities\VS2010\MAIN\Source\Activities\Framework\AssemblyInfo\AssemblyInfo.cs:line 610 at TfsBuildExtensions.Activities.Framework.AssemblyInfo.InternalExecute() in D:\Projects\teambuild2010contrib\CustomActivities\VS2010\MAIN\Source\Activities\Framework\AssemblyInfo\AssemblyInfo.cs:line 483 at TfsBuildExtensions.Activities.BaseCodeActivity.Execute(CodeActivityContext context) in D:\Projects\teambuild2010contrib\CustomActivities\VS2010\MAIN\Source\Common\BaseCodeActivity.cs:line 67.
when I try to update AssenblyFileVersion. I tryed following values:
- "1.1.1.1";
- “$(current).$(current).$(increment).$(date:yyyy)“
Nothing seems to be working.

andyste1 May 14, 2012 at 10:04 AM 
Does this check the files out (and back in after editing)?

And can I use it to set the version number where the "revision" is taken from the TFS build number (the value that appears at the end of the default TFS build version number, and increments with each day's build)?