Thursday, 31 October 2013

TFS - Lab Build - Create Zip File with Build Output in the Drop Folder

Sometimes it takes long time to copy files from drop folder to the lab environment when you have your lab environment in different locations( distributed environments), and you have several hundred files in your drop folder (example - published website with lot of files).

I will explain how to use a Build Activity to zip, by customizing LabDefaultTemplate.11.xaml.

How to add a custom code activity to a build template is clearly explained in this article http://www.ewaldhofman.nl/post/2010/04/29/Customize-Team-Build-2010-e28093-Part-4-Create-your-own-activity.aspx

Go through the above article if you want to know the basics.

So lets look at how to add a build activity to zip the build output.

1. First you need to have a code activity similar to below


2. Once compiled and add reference to your build template project you can view the New Activity --> Zip in the Toolbox when you open the build template.


3. Drag and drop the  Zip activity to LabDefaultTemplate.11.xaml after the "Compute build location needed" activity to make sure BuildLocation variable is filled with the correct build location (This variable will contain the Build Folder path of the Build queued or used by the Build task of the Lab Workflow).



4. Set the properties as below in the Zip build activity. DirectoryLocation is set to Build Location and Zip file path will be Build Location path with ".zip" extension. This will make sure zip file is created at the drop location of the build used by the lab workflow.


5. Create a build definition using the lab template and set the lab workflow build step to use the release build definition of yours (Output of this build will be used to create the zip file).


6. Queue a build with the lab build and you will see lab(build-deploy-test) build, queues  the release build, once complete use the build location and create the build output as a zip file.


7. In the drop location of the release build you will have the build out put files and the zip file of the output.


In my next post, I will explain "How to use a deployment task of the Lab Workflow to copy the output zip file and extract it in the Lab Environment Machine".

17 comments:

Anonymous said...

G8

Anonymous said...

How can I find 'compute build location needed activity'

Chaminda Chandrasekara said...
This comment has been removed by the author.
Chaminda Chandrasekara said...

Open the LabDefaultTemplate.11.xaml in Visual studio. The post http://www.ewaldhofman.nl/post/2010/04/29/Customize-Team-Build-2010-e28093-Part-4-Create-your-own-activity.aspx explaines how to open a build template in Visual Studio (Same can be done with VS 2012).

You can find the Compute Build Location Needed activity in that

Anonymous said...

Thanks Chaminda for your answer. My solution is failing right now because of following error

The primary reference
"\BuildTask\bin\Debug\BuildTask.dll"
could not be resolved because it has an indirect dependency on the framework assembly "System.IO.Compression.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework.

Any ideas?

Anonymous said...

Is it possible to get your full source code.

Anonymous said...

Actually I included one of the warnings in last post. Error is -
Could not find type 'BuildTask.Activities.Zip' in assembly 'BuildTask'.
Error is thrown from CustomTemplate.xaml in the template project. I used the instruction in the provided link to create the

build activity, which asks for two projects to be created, which in my case is BuildTask and Template (has project

reference to BuildTask.dll gets created every time though.


Not sure if it matters, I think you used TFS 2013 which is compatible to .net framework 4.5. The ZipFile class is defined

in 4.5. I'm using TFS 2010 and VS 2010 ultimate which is compatible to 4.0.

Just out of curiosity, I also tested zipping up a folder using ZipFile class, but targeting framework 4, in a simple

console app using VS2010. It worked fine.

One more question - Will I need to add Template.dll (once I'm able to successfully compile it :)) to the folder in repo

where BuildTask.dll is put, so build controller can find it?

Chaminda Chandrasekara said...

Let me understand your question first. Your Code Activity is in BuildTask.dll? With that understanding ..you only need to have BuildTask.dll in "Version control path to custom assemblies" for the build controller to locate it and no need to have Template.dll in there.

I am using the above currently with TFS 2012, and have tested on TFS 2013 as well. But this should not give any problems in the TFS 2010 as well since it is nothing but just a code activity doing the zip file creation. One more question come into my mind is "Do you have necessary visual studio version (2010 in your case) installed in the build server machine?". It is a good idea to have necessary visual studio version installed in your build server.

Anonymous said...

Yes I do have visual studio in the build machine. Now I'm seeing this error after queueing build (this is from build explorer log -

Copy Files to Drop Location

00:00

Zip
Could not load file or assembly 'System.IO.Compression.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.

Do I need to add the assembly to the folder where BuildTask.dll is in TFS

Also I'm using the defaulttemplate. Do you know where I can put the zip activity in the workflow. I added it somewhere, which I ran this build again. But I can't find it (guessing its a common problem!)

Anonymous said...

Yes my Code Activity is in BuildTask.dll. My setup is exactly like ewald's link that you provided. And all the compile issues are fixed now. I'm seeing run-time errors now as I pointed out in the last post.

Anonymous said...


Now I'm seeing following error

TF215097: An error occurred while initializing a build for build definition \xxx\xxx-custom: Cannot create unknown type '{clr-namespace:BuildTask.Activities;assembly=BuildTask}Zip'.

I do have the

Anonymous said...

I do have [BuildActivity(HostEnvironmentOption.All)] in my code.

I get this error almost right away.

The only change I can think of is adding System.IO.Compression.FileSystem.dll to the folder in TFS where I have BuildTask.dll.

I also added BuildTask.dll to GAC in the build server per somebody's suggestion with no effect. I have no idea why all of a sudden I'm getting TF215097 error. Last time the error was in run-time after queueing build and running all the previous steps successfully, when code hit the step containing the custom activity (could not load System.IO.Compression.FileSystem.dll).

Anonymous said...

One more thing - did you add the dll coming out of the Template project which the xaml file is added to, to the folder in TFS containing BuildTask.dll. Ah well, being at my wits end with this thing, I added that there as well as in the GAC of the build server. Didn't work.

Anonymous said...

TF215097 error went away after restarting the build service. So I'm back to my original error.

From build explorer -

Copy Files to Drop Location
Skipped execution of Revert Workspace because of BuildReason Manual

00:00
Zip
Could not load file or assembly 'System.IO.Compression.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.

Chaminda Chandrasekara said...

Sorry, I realize this a little late..(since I always have VS2010,2012,2013 available I completely missed which gives which) If you are using the sample I have shown in my post..The ZipFile Class is available only in VS2012 with framework 4.5

So for you maybe third party assembly may work, and is you go for third party dll you need to add it to custom assembly location of the build controller..or you can install VS 2012 in you build server..
Hope this link will help you on why and some third party options http://stackoverflow.com/questions/19740099/system-io-compression-filesystem-assembly-in-vs-2010

Anonymous said...

Installing .net 4.5 in the build box fixed the issue. Thx for your help.

john alex said...

nice write up. Fix path too long error while extracting a ZIP file.