Build Customization using Visual Studio 2010 – Part II

Posted by: Gouri Sohoni , on 4/23/2010, in Category Visual Studio
Views: 81855
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.

This article has been editorially reviewed by Suprotim Agarwal.

Absolutely Awesome Book on C# and .NET

C# and .NET have been around for a very long time, but their constant growth means there’s always more to learn.

We at DotNetCurry are very excited to announce The Absolutely Awesome Book on C# and .NET. This is a 500 pages concise technical eBook available in PDF, ePub (iPad), and Mobi (Kindle).

Organized around concepts, this Book aims to provide a concise, yet solid foundation in C# and .NET, covering C# 6.0, C# 7.0 and .NET Core, with chapters on the latest .NET Core 3.0, .NET Standard and C# 8.0 (final release) too. Use these concepts to deepen your existing knowledge of C# and .NET, to have a solid grasp of the latest in C# and .NET OR to crack your next .NET Interview.

Click here to Explore the Table of Contents or Download Sample Chapters!

What Others Are Reading!
Was this article worth reading? Share it with fellow developers too. Thanks!
Share on LinkedIn
Share on Google+

Author
Gouri is a Trainer and Consultant on Azure DevOps and Azure Development. She has an experience of three decades in software training and consulting. She is a graduate from Pune University and PGDCA from Pune University. Gouri is a Microsoft Most Valuable Professional (MVP)  - Developer Technologies (Azure DevOps), Microsoft Certified Trainer (MCT) and a Microsoft Certified Azure DevOps Engineer Expert. She has conducted over 150 corporate trainings on various Microsoft technologies. She is a speaker with Pune User Group and has conducted sessions on Azure DevOps, SQL Server Business Intelligence and Mobile Application Development. Gouri has written more than 75 articles on Azure DevOps, TFS, SQL Server Business Intelligence and SQL Azure which are published on www.sqlservercurry.com and www.dotnetcurry.com. You can connect with her on LinkedIn.


Page copy protected against web site content infringement 	by Copyscape




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