Lessons learned in upgrading my TFS 2010 Build templates to TFS 2012

Awaiting the Visual Studio 2012 Launch I am preparing our builds to work on TFS 2012. In my previous post I described that I updated the references and imported some namespaces and then everything worked!

Because there were some issues with our current builds, I decided to restructure our build since I am already working on it. I created a new solution in Visual Studio 2012 and splitted up all our custom activities in separate assemblies.

I did this because changes are then easily to isolate. When all the projects were created, I copied the source into the project, renamed the namespaces in the c# files and renamed the namespaces in the XAML files.

When I create a custom activity, I use a Activity (XAML) for the flow and when needed a CodeActivity for the custom code.

image

The Build process

When I was ready restructuring, I took the new Build DefaultTemplate and put my activities in. I pointed my Controller to a Version Control folder, and published my assemblies and new template.

Then it started…..I got errors. Strange errors. For example:

TF215097: An error occurred while initializing a build for build definition \<Project>\<Buildname>: Cannot create unknown type ‘{clr-namespace:<namespace>

Or

TF215097: An error occurred while initializing a build for build definition \XXX: The invocation of the constructor on type ‘<type>’ that matches the specified binding constraints threw an exception.

Or

Could not load file or assembly ‘Custom Activity’ or one of its dependencies. The system cannot find the file specified.

All strange because everything seemed to be right. After searching for several hours I found solutions. There is not one, but a combination of solutions. the list below lists all the actions I did in order to solve my build errors

  • Use target framework 4.5 for your template project and activity project

Because I created the projects in VS2012 it defaults to framework 4.5. When you change the target framework after the project and XAML files have been created, the format of the XAML stays in 4.5 format, causing errors. In order to solve this, open the Workflow as code, remove the sections

TextExpression.NamespacesForImplementation>  and TextExpression.ReferencesForImplementation

image

Save the file and open the designer again.

  • Remove the version from the namespace references

Open the XAML Code and remove all versions of assemblies. This issue is described here

  • Remove all unused namespaces from your workflows. Also check your XAML for unused assembly references

image

  • Put ALL referenced assemblies in the Source Control Folder that is used by the Build Controller.

I was using a zip component. This was not in my Assembly folder for the BuildController. The error I got was not mentioning this component, but only that it could not find my custom assembly

  • Beware of Assemblies with only XAML files

I had one assembly that did not contain custom code, but only a XAML workflow referencing some TFS Build Activities. When compiled and published to my Version Control Folder, my Build stated it could not find my assembly. What happened is that the build process could not create the generated type from my XAML, because there was no code behind. There must be some code that has the attribute     [BuildActivity(HostEnvironmentOption.All)]

This blog post of Hugo Häggmark helped me out a lot. Hugo describes to add a partial class to your project with the same name as your flow. Give the new partial class the BuildActivity(HostEnvironmentOption.All)] attribute and it works. So for example, if your xaml file is called ActivityTest.xaml, add a partial class ActivityTest in the same namespace, and decorate with the attribute.

After applying all these things, it worked!

Hope this helps!

3 Responses to “Lessons learned in upgrading my TFS 2010 Build templates to TFS 2012”

  1. Hello,

    I am currently working on getting my 2010 builds upgraded to using the newest binaries in order to make sure the the 2012 upgrade is as easy as I can make it; therefore, I’m wondering if it would be possible to have my custom assemblies library set to .net 4.5.
    Please note that I have

    Any help would be appreciated.
    Alex

Trackbacks/Pingbacks

  1. Upgrading a Custom Build from TFS 2010 to TFS 2012 « Jeremy's Development Blog - October 16, 2012

    […] https://osnabrugge.wordpress.com/2012/08/08/lessons-learned-in-upgrading-my-tfs-2010-build-templates-… […]

%d bloggers like this: