DotNetCurry Logo

Build Customization using Visual Studio 2010 – Part II

Posted by: Gouri Sohoni , on 4/23/2010, in Category Visual Studio, VSTS & TFS
Views: 74264
Abstract: In the last article Build Customization using Visual Studio 2010, we discussed new features provided for Build Management and how to customize the default template and use it in a build definition. In this article we will discuss how to create a new activity and make it available in the toolbox with the help of activity library.
In the last article Build Customization using Visual Studio 2010, we discussed new features provided for Build Management and how to customize the default template and use it in a build definition. In this article we will discuss how to create a new activity and make it available in the toolbox with the help of activity library.
In this demonstration, we will see how to add a new activity for a ‘Warning Message’ after creating the activity using Activity Library Template.





Let us start by creating a project of the type ‘Activity Library’

RecentTemplate
Even though we will be working with xaml, we need to add a new item named Code Activity

ActivityLiabrary
The project being created needs to have references to  Microsoft.TeamFoundation.Build.Client.dll from <drive name>\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ReferencedAssemblies\V2.0. The reference to System.Drawing  is also required otherwise we end up getting a compilation error.
The class in the ‘Code activity’ needs to have the attribute of BuildActivity (HostEnvironmentOption.All)
By default the target framework is set to client profile which does not support the classes we are using. So change the target framework from .NET Framework 4 Client Profile to .NET Framework 4.
Now we will actually add the activity by opening xaml. For getting all the items for Team Foundation build workflow, we add new items to the Toolbox by choosing Microsoft.TeamFoundation.Build.WorkFlow.dll from <drive name>\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies
As we are also going to display warning message with this demonstration, drag and drop ‘WriteBuildWarning’ activity from the toolbox and provide message “demo warning” as string in the expression editor.

Expand
Build activity library. The next step is to create a custom definition for Build by using Team Explorer. It is always better to create a copy of existing build process template for doing changes rather than changing the existing template.
BuildProcessTemplate 
We need to add the activity we created with the ‘Activity library’ to this template. For this, we create a branch for custom template and map it to the location where the activity library exists

Browse
Check in pending changes for the branch and check out the branch for edit. It will be available in the folder for activity library. Add the xaml as existing item to the ‘Activity library’ project (make sure to view xaml files). We require this step to view the newly created activity in the toolbox.
Now you can drag and drop the custom activity onto the designer  as shown.

Sequence

Some changes to the code are still required. Open the code and add the namespace xmlns:<ns>="clr-namespace:<ActivityNamespace>;assembly=<AssemblyName>" to build process root element. Add the activity <ns>:<ActivityName> > to the build process (use the same namespace provided). Save the file in the location which is mapped to the branch.
We need the activity library dll also available on server side. Check in activity library by including the dll for it in the project. This makes the dll available on server side which is required for the custom build definition. Merge the branch to the original template and check in.
We need to change the build controller to specify the path for custom assembly. It should be the same where the activity library dll is checked in. Note: If there are multiple custom assemblies, it is better to create a folder in BuildProcessTemplate and provide it as path.
Queue the build and check for the working.

DemoWarning

The warning message can be seen when the build gets executed.
In next article we will see how to create a custom activity using code.
Was this article worth reading? Share it with fellow developers too. Thanks!
Share on LinkedIn
Share on Google+
Further Reading - Articles You May Like!
Author
Gouri Sohoni is a Trainer and Consultant for over two decades. She specializes in Visual Studio - Application Lifecycle Management (ALM) and Team Foundation Server (TFS). She is a Microsoft MVP in VS ALM, MCSD (VS ALM) and has conducted several corporate trainings and consulting assignments. She has also created various products that extend the capability of Team Foundation Server.


Page copy protected against web site content infringement 	by Copyscape




Feedback - Leave us some adulation, criticism and everything in between!