Build Customization using Visual Studio 2010 (TFS 2010) - Creating Custom Activity
Posted by: Gouri Sohoni ,
on 6/10/2010,
in
Category VSTS & TFS (Azure DevOps)
Abstract: In this article we will discuss how to create a custom activity using code and make it available in the toolbox with the help of activity library.
In this article we will discuss how to create a custom activity using code and make it available in the toolbox with the help of activity library.
Follow these steps:
Step 1: Create a project for activity library
Step 2: Add new item named Code Activity
Step 3: Add references to the following assemblies –
Microsoft.TeamFoundation.Build.Client.dll from <drive name>\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ReferencedAssemblies\V2.0
and
Microsoft.TeamFoundation.Team.WorkFlow.dll from <drive name>\Program Files\Microsoft Visual Studio 20.0\Common7\IDE\PrivateAssemblies (Take care of processor related Program Files folder)
Step 4: Provide the attributes of BuildActivity(HostEnvironmentOption.All) and BuildExtension(HostEnvironmentOption.All) to the class.
Step 5: Change the target framework from .NET Framework 4 Client Profile to .NET Framework 4. By default the target framework is set to client profile which does not support the classes we are using.
Step 6: Now we will add the actual code. For this code we will use the following namespaces
-Microsoft.TeamFoundation.Build.Workflow.Tracking
-Microsoft.TeamFoundation.Build.Workflow.Activities
-Microsoft.TeamFoundation.Build.Client
The code looks as follows:
C#
[BuildActivity(HostEnvironmentOption.All)]
[BuildExtension(HostEnvironmentOption.All)]
public sealed class CodeActivity1 : CodeActivity
{
public InArgument<string> Text { get; set; }
public InArgument<IBuildDetail> currentBuild { get; set; }
protected override void Execute(CodeActivityContext context)
{
string buildNumber = "Build Number: " + this.currentBuild.Get(context).BuildNumber;
context.Track(new BuildInformationRecord<BuildMessage>()
{
Value = new BuildMessage()
{
Importance = BuildMessageImportance.Normal,
Message = "This is a custom information node",
},
});
}
}
Step 7: Build activity library and Create a custom definition for Build by using Team Explorer.
Step 8: Create a copy of the existing build process template for doing changes
Step 9: Create a branch for the custom template and map it to the location where the activity library exists
Step 10: Check in pending changes for branch. Check out the branch for edit. It will be available in the folder for activity library.
Step 11: Add the xaml as existing item to activity library project (make sure to view xaml files). We require this step to view the newly created activity in the toolbox.
Step 12: Now you can drag and drop the custom code activity onto the designer
Step 13: Open the code and add namespace xmlns:<ns>="clr-namespace:<ActivityNamespace>;assembly=<AssemblyName>" to build process root element. Add the activity <ns>:<ActivityName> > to build process. (Use the same namespace provided in previous step)
Step 14: Save the file in location which is mapped to the branch. Check in activity library by including dll for it in the project. This makes the dll available on server side which is required for the custom build definition.
Step 15: Merge the branch to the original template and check in. Change the build controller to specify the path for custom assembly. It should be the same where the activity library dll is check-in. (If there are multiple custom assemblies it is better to create a folder in BuildProcessTemplate and provide it as path)
Step 16: Queue the build and check if the code activity is working.
The build number can be seen when the build gets executed.
Conclusion: This article was the last part of the Build Customization Series. In this article we saw how to create a custom activity using code and make it available in the toolbox with the help of activity library.
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!
Was this article worth reading? Share it with fellow developers too. Thanks!
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.