Error when copying Build Template “The type ‘TfsBuild.Process’ already contains a definition for…”

I do quite a lot of Build customizations and usually I create a new Build Template for each type of Build I want to do.

You can choose to copy the file in the Build Definition Editor or you can just Copy/Paste the file in Windows Explorer. The advantage of the editor is that it directly copies the file to Source Control.

image

When you do Build Customizations, it is necessary to have a solution that contains a project with the templates, and a project with your custom activities. In my case I have a template project that contains all my different Build Template XAML files. When you copy a template and build the solution, the following error pops up.

The type ‘TfsBuild.Process’ already contains a definition for…”

What is happening here?? It even gives you this message when you copy it from the Build Definition Editor.

The Build Template is a XAML file and is handled that way by the compiler. If you open the properties of your Build Template file in the solution explorer, the Build Action is set to XamlAppDef for Workflow files.

image

When this is the case, source is generated each time when you build. You can set the Build Action to None to fix the problem. However, this does not compile the workflow and you can not programmatically call this.

Sometimes you want to achieve this and thus set the Build Action to XamlAppDef. When you have 1 workflow everything is fine, When you copy the workflow the problems start. The code that is generated on compile time looks in the xaml file to obtain the namespace. Because you copied the file, the namespace is the same and the same class is generated for different workflows.

To fix this right click the Build Template XAML file and choose View Code.

image

In the first line there is the name of the generated class

image

Rename this to something you like. For example TfsBuild.BlogExampleTemplate

Keep the “TfsBuild” for now….

The rest of the file points to <this:Process

Replace all occurrences of this:Process with this:BlogExampleTemplate.

That’s it. Reload the file and you’re done.

If you also want to change “TfsBuild” in your own namespace for example “Company” change the x:Class attribute in "MyCompany.BlogExampleTemplate” and the

xmlns:this="clr-namespace:TfsBuild;" 
in  
xmlns:this="clr-namespace:MyCompany;"
Good luck !
Advertisements

One Response to “Error when copying Build Template “The type ‘TfsBuild.Process’ already contains a definition for…””

  1. Thanks! Worked perfectly!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: