Moles issue when multiple projects reference the same moles assembly and the assembly version changes

Background

The other day I had one of the teams at my current customer report a strange build error in TFS build. They could tell that it had something to do with Moles but they couldn’t solve it.

The solution they were trying to build was pretty simple and consisted of on Class Library project and two Test projects, one for unit testing and the second for integration testing. It looked something like the picture below:
image

Challenge

I noticed right away that both test projects had moles references to the library which doesn’t have to be a bad thing. But then I also noticed that one of the test projects had a reference to the other test project as well. Could this result in a conflict resolving the correct Moles assembly?

Well if you DO NOT change the assembly version of the library project then you WILL NOT have a problem. But if you’re like us and like to sync your AssemblyVersion and AssemblyFileVersion with the build in TFS then you will run into this trouble. You’ll probably get an error message like:

The type or namespace name ‘Moles’ does not exist in the namespace (are you missing an assembly reference?)

Mind you that this error message is a common compile error in Moles but does also appear in this case. I’ve attached a small solution that mimics this behavior here. (you will need VS2010 and Moles installed to build the zipped solution)

Solution

You get this error because when you add a Moles reference in your test project it adds a reference to a specific version of the Moled assembly (this is of course the default behavior you want in most cases) but when two assemblies have the same Mole reference and they reference each other we get a copy conflict.

To solve this I’ve come up with these solutions:

  1. First of all you should probably break the project reference between the two test projects and then your problems will automatically go away.
  2. When you add a Moles Reference from within Visual Studio you’ll get a reference to a specific version like so:
    <Reference Include=Type.Moles, Version=1.0.0.0, Culture=neutral
    , processorArchitecture=MSIL
    />
    If you change the property Specific Version on the Moles reference to False then that will solve this issue as well.
    image

I wish that the command “Upgrade .Moles files..” on the solution level would automatically update the project references with the new versions of the Mole References. But I believe I have to file that request to Microsoft.
image

Enjoy,

Hugo

The build process could not be deserialized due to…

Background

At my current customer we’ve upgraded all our builds from TFS 2008 MSBuild tasks to TFS 2010 WorkFlow Activities. I must say that we’ve gone from several common target-files and per-build specific rsp-files to ONE build process template! That says enough about the power of the new build process in TFS 2010.

Following Microsoft’s recommendation here we’re using one Build Controller for our Default Collection and we’ve centralized our custom activities to one Team Project; lets call it Central.

In the Team Project Central the custom activities we’re using a stored at $/Central/BuildComponents and our Build Controller points out this location as the picture shows below:

image

In our Custom Activities we have some simple serializble objects that we use as part of our process to store some settings that we need in our build process. An of that would be an XCopyFileWrapper that we use to store 3 string properties:

image

We then use this wrapper in our Meta Data property in our DefaultTemplate.xaml file like the picture shown below:

image

Then we added the ParamWrapper as an array of XCopyFileWrapper and add it as an argument to DefaultTemplate.xaml like so:

image

This way we can have the same DefaultTemplate XCopy files depending on the input we add for each unique build definition in this rather nice centralized GUI for your build definitions:

image

image

And then in our DefaultTemplate.xaml we have an foreach loop that loops over our array of XCopyFileWrappers and invokes XCopy! This makes our build definitions really sweet, dynamic and expandable right!

The challenge

So the next Team Project comes along we can call it Project B and they want to use our Build Process. So they branch our build process template into their project and they create a new build definition and then KAPOW!

image

What happen here! Well my initial thoughts was another lesson I learned previously and blogged about here but specifying the assembly in the DefaultTepmplate.xaml didn’t solve this issue.

The solution

The very simple solution to this problem is that you need to give users READ permissions to your BuildComponents folder in our case the $/Central/BuildComponents folder (another way is to solve this is to give other users READ permissions to the Central Team Project).

That’s it!

Reflection

  • So if I want to centralize my custom build components then I have to give all users that will use these custom build components READ permission to the folder where the components are stored.
  • Or you could have some sort of deployment mechanism that deploys the build components to every Team Project in the Team Project Collection but then you’ll have to have one Build Controller per Team Project.

Cheers,

Hugo

Stuck on “Cannot create unknown type {clr-namespace:” in TFS Build?

Background

A couple of days ago I was upgrading some of my clients MSBuild tasks to WorkFlow Activities following the “Rewrite MSBuild task as a Workflow Activity” option in the guidelines from this excellent post by William Bartholomew.

I stumbled upon a custom Assembly Versioning MSBuild task and I took a moment of thought to see what I could do to improve this MSBuild task. I read this great post by Mike Fourie’s and yet another great post by John Robbins that I really encourage anyone doing custom versioning in TFS 2010 to read.

I decided to follow some of the posts recommendations and decided that for the purposes of my client I would not need to convert this (former) MSBuild task into a coded CodeActivity because a designed activity would be more then enough.

Anyway a simplified version of the clients workflow activity looked something like this:
image

With some input arguments that looked like this:

image

Everything is pretty straightforward if you’re custom to TFS Build and Windows Workflow Foundation except for the Activites in the Then/Else sections. In the Then/Else sections I’m using the AssemblyInfo Activity from Community TFS Build Extension here.

Challenge

So I check-in my custom assembly and make sure that the controller is pointing to the folder in the source control tree that contains my custom assemblies.
image

I then added my new Activity to the build process template and ran my first build against that build process template…BOOOOOM! Got this message: TF215097: An error occurred while initializing a build for build definition \Tailspin Toys\HugoHaggmark: Cannot create unknown type ‘{clr-namespace:HugoHaggmark.TfsBuild.Activities}Example’.

image

Solution

Are you in the same situation as me? Don’t despair a simple solution is close. Ler

  1. Firstly open up build process template as XML.
  2. Find the reference to your Custom Activity in the XML (probably in the top section of the XML), looks something like this:
    xmlns:local=”clr-namespace:<YourNameSpace>” or in my case I had this:
    xmlns:local=”clr-namespace:HugoHaggmark.TfsBuild.Activities”.
  3. Add ;assembly=<Name of your assembly> to that reference so in my case the end result looked like this:
    xmlns:local=”clr-namespace:HugoHaggmark.TfsBuild.Activities;assembly=HugoHaggmark.TfsBuild.Activities”
  4. Create a partial class right next to your Custom Activity and add the BuildActivity attribute like shown below:
    image
  5. Check In, rebuild and redeploy assemblies to the custom assemblies folder.
  6. Run the build and voila! The build error is gone!

Cheers,

Hugo