Maybe you still have doubts about my introduction to tianma xingkong in the previous section. For example, in the previous demo, I only used the string type, for collections and user-defined entities, they are not touched.ArticleAnd then cover these details. Also, many articles will talk about the magical metadata, but I did not mention it, because this argument still has many details to detail,
In addition, I think the readers are more curious about the activities that vstf team provides for us to build.
In the previous demo, we used writebuildmessage in team Foundation build activites. This activity is used to output some information in build log.
The remaining 40 activities have their own purposes. For example, the template XAML we are currently using is composed of these activities and some activity that comes with WF 4.0. I will introduce these activities in my post studying defaulttemplate. XAML.
Can we write some build activities with custom logic and use them in the template XAML?
Yes, you can, but it is very troublesome.
The basic idea is:
1. Customize some codeactivities, all of which are derived from a workflow base class. Only in this way can we display our defined argument in the build template and execute the custom logic,
2. Package the codeactivity into a DLL. We need to put the DLL in a location known to vstf.
Objectives:
Write an activity that can process data and add "hello," to the name of each input person.
After clarifying our ideas and determining our goals, we will start to practice them.
1. Create an SLN project and check in to vstf. It includes two class libraries:
, Buildengine is used to place all custom activities, while buildtemplate is used to place all templates.
2. Add reference
Add the DLL that the vstf team provides for us to build workflow. For more information, see which one is missing and which one is missing:
You may not be able to find the location of the DLL with workflow. Please find the following two directories:
C: \ Program Files \ Microsoft Visual Studio 10.0 \ common7 \ ide \ referenceassemblies \ V2.0 \
C: \ Program Files \ Microsoft Visual Studio 10.0 \ common7 \ ide \ privateassemblies \
For Microsoft. teamfoundation. testimpact. client. DLL. You may not be able to find this DLL. Please click here to download it and check it in your vstf, because we will keep using it later.
At the same time, add a reference to the buildengine project in the buildtemplate project, because we need to add a custom activity to the template.
3. Start to write the first activity.
First, add a new code activity in vstf and name it messagehandler. Right, we just want to simulate the writebuildmessage activity that the vstf team used in the previous demo provides to us.
Vstf will automatically generate some code for us. We keep its skeleton and slightly modify it as follows:
FromCodeThe built-in comments shows that it has a text attribute. If we drag the activity messagehandler to workflow, the text will be exposed in the attribute panel, we can set it.
In addition, we need to add an attribute for messagehandler to be recognized by vstf:
4. Copy the original defaulttemplate. XAML (which comes with vstf without any changes) to the buildtemplate project, rename it customtemplate1.xaml, and change its build action to xamlappdef.
Compile the buildengine project. When you switch to the buildtemplate project, you can see the newly generated messagehandler in the toolbox of mmtemplate1.xaml on the visualization page.
Friendly reminder: please save the original defaulttemplate. XAML. We prefer to copy a copy, rename it each time, and then make changes on it, and will not directly modify the original file.
5. Open customtemplate1.xaml and create an argument named messagea:
6. Drag messagehandler from toolbox to the position in, that is, get the build activity, and set text to mymessage in the messagehandler attribute panel:
7. Drag a writebuildmessage from the toolbox to messagehandler, and set message to mymessage in the writebuildmessage attribute panel:
8. Check the modified customtemplate1.xaml file in vstf.
So far, we have completed the coding of a custom build activity.
There are many things to do next. First, how do I know the position of customtemplate1.xaml during build?
To solve this problem, open the build panel. Under the "process" tab, we can see that in the upper right corner, we can select the dafault template. The next operation steps are as follows:
1) Click the new button to open the new build Process Template panel.
2) In the new pop-up panel, we can copy an existing template to the target location, or directly select the template at a location of vstf. Here we use the latter, so click the Browse button.
3) The Browse dialog box is displayed. Let's find the position of customtemplate1.xaml on vstf.
4) Select "OK" all the way to get the following picture:
Wait, it's not over yet. If you can't wait to execute the build immediately, you will get the following error log:
The reason is that vstf does not know where the messagehandler we wrote and Its DLL -- buildengine. dll are, so it cannot be parsed when executing this activity.
You may immediately think that it would be great to put buildengine. dll in GAC. However, this is not a perfect solution, because whenever you install a new build machine, you need to install the relevant DLL into the GAC.
Another solution is to place buildengine. dll on vstf to let vstf know where the DLL is located. At the same time, this dll will be updated every time the buildengine project is compiled successfully. The detailed steps are as follows:
1. Put buildengine. dll on vstf.
2. Let vstf know where the DLL is located. Right-click builds and select Manage build controllers from the menu.
Select the controller of the agent you are using and click Properties:
In the pop-up dialog box, we finally found the place where you can select the custom build activity path and specify it as the directory where buildengine. dll is located:
In the future, as long as we use the agent under this controller to execute build, we will check the DLL in the $ baobaoagile/buildassemblies directory and try to load it.
Finally, we will automatically update the file on vstf after each successful compilation. Right-click the buildengine project to open the property form, go to build events, and enter the following script in the Post-build window:
The first line of script will checkout the buildengine. dll file on vstf to the local path
The second line of script copies the newly generated buildengine. DLL to the local path corresponding to vstf. Note that the first parameter here is the location of the source file. Make sure that this path is correct.
The last line of script checkin this file
The actual path for running is as follows:
You can observe buildengine. dll on vstf. Every time buildengine is compiled, the update time of buildengine. dll will be updated.
Now we can safely execute build. Before Execution, set the messagea attribute to Baobao In the build panel:
Run build. We can see that hello and Baobao are successfully printed in build log.
Download the code in this article: wfbuildsolution