Build Customization using Visual Studio 2010 – Part II
Posted by: Gouri Sohoni
in Category Visual Studio
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’
Even though we will be working with xaml, we need to add a new item named Code Activity
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.
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.
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
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.
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.
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.
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!