VS 2010 Build Customization: Custom Activity Invoke Process

Posted by: Gouri Sohoni , on 11/30/2011, in Category Visual Studio, VSTS & TFS
Views: 75543
Abstract: In this article, we will discuss how to call an activity Invoke Process by customizing the process template in Visual Studio 2010.

In this article, we will discuss how to call an activity Invoke Process by customizing the process template in Visual Studio 2010. This article is in succession with previous articles for Build Customization Build Customization: Custom Activity with code, Build Customization: Custom Activity with xaml and Build Customization by Changing process template. I would suggest you to read these articles first to understand the flow.

This article uses a virtual machine which can be downloaded
over here.

Step 1. Login as Abu Obeida Bakhach (Dev) with password as P2ssw0rd

Step 2. Create a workflow activity library named CustomActivity. Start Visual Studio 2010 from Microsoft Visual Studio 2010. Select File > New Project. Ensure that the language selected is C#.

 

Step 3. Select the project template of Activity Library and enter the name as CustomActivity and click the Ok button. Ensure that Add to Source Control option is checked

vs2010-build--invoke-process1

Make sure to specify the location in Iteration 2 in Development branch

vs2010-build--invoke-process2

Step 4. Add Code Activity to the project

vs2010-build--invoke-process3

Step 5. Right click on the project in Solution Explorer and select properties. Change the target framework from client to full.

vs2010-build--invoke-process4

Click on the Yes button.

Step 6. Add references to following assemblies

Select the project template of Activity Library and enter the name as CustomActivity and click the Ok button. Ensure that option is checked Make sure to specify the location in Iteration 2 in Development branch Add Code Activity to the project Right click on the project in Solution Explorer and select properties. Change the target framework from client to full.Click on the Yes button. Add references to following assemblies

 

  • Microsoft.TeamFoundation.Build.Client, Microsoft.TeamFoundation.VersionControl.Client and Microsoft.TeamFoundation.WorkItemTracking.Client from C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0
  • Microsoft.TeamFoundation.Build.WorkFlow from C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies
  • System.Drawing from .NET tab

Step 7. Add an attribute to the code activity class as [BuildActivity(HostEnvironmentOption.All)] after including the reference to the following:

using Microsoft.TeamFoundation.Build.Client;

Step 8. Create a new build definition with the name as “Tailspin Toys Invoke Process”.

Step 9. Keep default trigger as Manual and specify workspace as follows. If custom activity does not appear, you will have to check in.

vs2010-build--invoke-process5

Step 10. Specify output folder in Build Defaults tab as
\\WIN-GS9GMUJITS8\drops as shown below

vs2010-build--invoke-process6

Step 11. Ensure that the Items to build dialog box contains both the solutions for custom Activity and Tailspin Toys, as shown below

vs2010-build--invoke-process7

Step 12. Remove any automated tests to be executed on Build. In the process tab, select automated test and click on the Remove button. Click OK.

vs2010-build--invoke-process8

Step 13. Create a copy of the default template and name it as “InvokeProcessBuildProcessTemplate.xaml”

vs2010-build--invoke-process9

Make sure that the items to build has the selected custom activity, as well as the tailspin toys solution. Also make sure that no automated tests are to be executed as BVT. Save the build definition.

Step 14. Create a branch for InvokeProcessBuildProcessTemplate.xaml in the following manner as shown below, by using the Source Control Explorer.

vs2010-build--invoke-process10

Ensure the target folder is pointing to CustomActivity.

Step 15. Let us now create a console application which will be invoked using Invoke Process Activity. Right click on the solution in Solution Explorer and select the option of Add New Project. Select the project type as Console Application and provide name as ConsoleAppCreateFile

vs2010-build--invoke-process11

Step 16. The code will be similar to the following

static void Main(string[] args)
{
using (System.IO.StreamWriter sw = new
System.IO.StreamWriter("c:\\Test.txt"))
{
sw.WriteLine("Doing Code Analysis with Special tool");
}
}


Build the console application.

Step 17. Right click on the project name (CustomActivity) in Solution Explorer and select the option as Add New Item and the item of type Activity.

vs2010-build--invoke-process12

Specify the name as InvokeProcess as shown

Step 18. Drag and drop InvokeProcess activity from Toolbox on the designer. Drag and drop WriteBuildMessage and WriteBuildWarning as shown below:

vs2010-build--invoke-process13

Configure the properties for InvokeProcess, WriteBuildMessage and WriteBuildWarning

Step 19. Specify a constant value for Message property in WriteBuildMessage and WriteBuildWarning. For InvokeProcess, specify file name as follows

"c:\users\abuobe\documents\visual studio 2010\Projects\CustomActivity\ConsoleAppCreateFile\bin\Debug\ConsoleAppCreateFile.exe".

This is the path for the console application. Save the xaml file.

For Custom Activity add references to System.Activities.Presentation, PresentationFramework and WindowsBase. Close InvokeProcess.xaml file and Build the custom activity project. In case you get an error for the .dll file, right click on the file and specify Check out for edit.

Step 20. Right click on CustomActivity and select the Add Existing Item and add the branched xaml file. Set the Build Action
as None for this file.

vs2010-build--invoke-process14

Step 21. Open the file, collapse the sequence and add the InvokeProcess activity as follows

vs2010-build--invoke-process15

Save and close the file.

Step 22. Right click on the file in solution explorer and select View Code. Change local to ssgs.

vs2010-build--invoke-process16

Also change local to ssgs where InvokeProcess appears.

Step 23. Close and save the file. Check in the branch, merge to its original and check in.

vs2010-build--invoke-process17
vs2010-build--invoke-process18

Step 24. Ensure that the CustomAssembly.dll is also checked in. Right click on Builds from Team Explorer. Specify the custom assembly path as follows

vs2010-build--invoke-process19

Step 25.  Right click on the build and select queue new build. After successful execution of the build, the txt file gets created on C drive and the log shows execution of invoke process as follows.

vs2010-build--invoke-process20
 
 
That’s it! These were the steps to call an activity Invoke Process by customizing the process template in Visual Studio 2010.

Give a +1 to this article if you think it was well written. Thanks!
Recommended Articles
Gouri Sohoni is a Microsoft MVP, Trainer and consultant for over two decades. She is a Microsoft Certified Trainer (MCT), MCITP and has conducted several corporate trainings on Microsoft technologies that include Visual Studio 2010 (ALM), SQL Server 2008 BI, SQL Server 2008 developer track, SQL Server 2005 BI, SQL Server 2005 developer track etc.


Page copy protected against web site content infringement by Copyscape


User Feedback
Comment posted by tripathi manisha on Thursday, December 15, 2011 9:45 AM
nice work do mam
Comment posted by fastwindowstweaker on Tuesday, January 17, 2012 2:38 AM
Hello. i am <a href="http://www.fastwindowstweaker.com/">fastwindowstweaker</a>.Thanks for sharing this useful article with us.That's really helpful.
Comment posted by fastwindowstweaker on Tuesday, January 17, 2012 2:41 AM
hello, i am fastwindowstweaker. Thanks for sharing this useful article with us.That's really helpful.
http://www.fastwindowstweaker.com/

Post your comment
Name:  
E-mail: (Will not be displayed)
Comment:
Insert Cancel