Build your old VB6 projects with TFS 2012

or How to edit a TFS 2012 build process template

A few weeks ago, I blogged about using VB6 with TFS 2012. The build process I proposed was relying on a MSBuild script that you had to check-in into TFS. This script was responsible for calling VB6 on the command line and generate your VB executables. I just felt like something was left unexplored here, and I wanted to provide a little bit more sophisticated alternative for building your VB6 apps. So let’s customize the build workflow for the sake of our VB6 projects!

This post is also a tutorial for editing a TFS 2012 build process template!

The plan

We will modify the Default Template in order to make it compatible with VB6 projects. In the Solutions to Build process parameter, we want be pass a list of .NET solutions (.sln files), but also .vbp files. We will rely on some external activities to invoke VB6 compilation commands.

We’ll try to support the Ouputs clean option of regular builds, because it is useful for continuous Integration.

Set up your environment

We’ll be using the latest Community Build Extensions, you may download them and place the appropriate binaries in the custom assemblies folder that you have configured in your controller. If you don’t know about what I’m talking about, check out my A small guide to edit your TFS 2012 build templates and I hope you’ll be sorted.

Duplicate the Default Template, rename it something like DefaultTemplateVb6. If you want to be able to edit both files at once, follow this procedure I wrote that will avoid unwanted compile errors.

Build process changes

Open your build process template and go to Run On Agent => Try Compile, Test, and Associate Changesets and Work Items. Now look for the Try to Compile the Project TryCatch activity, you should double-click on its icon to “focus” the Workflow edition on this subcontent – it’s just more comfortable.

We are here at the heart of the loop that calls MSBuild on every project to build. We will need to store the result of the last VB6 compilation. For this, we need a variable in the scope of the Compile the Project block. Add a vbReturnCode variable as follows:

image

We want to run MSBuild on regular projects, and launch VB6 on .vbp projects. So we’ll add an If activity in order to filter VB6 projects. Insert it just before the Run MSBuild for Project activity.

Add a Sequence in the Then block, and drag the existing MSBuild activity in the Else block. Actually, recreate following piece of workflow:

clip_image001

Remember to add the custom activities in the toolbox in order to use them in the workflow (right-click and Choose Items…).

 

  • If “If Project Is VB6”
    • Condition: localProject.EndsWith(“.vbp”, StringComparison.InvariantCultureIgnoreCase) Or localProject.EndsWith(“.vbg”, StringComparison.InvariantCultureIgnoreCase)
    • Then
      • Sequence “Process VB6 Project”
        • VB6
          • see picture below for parameters
        • If “If VB Return Code” (see picture below)
          • Condition : vbReturnCode = 0
          • Then
            • SetBuildProperties “Set Compilation Status to Suceeded”
              • PropertiesToSet : CompilationStatus
              • CompilationStatus : BuildPhaseStatus.Suceeded
          • Else
            • SetBuildProperties “Set Compilation Status to Failed”
              • PropertiesToSet : CompilationStatus
              • CompilationStatus : BuildPhaseStatus.Failed
    • Else
      • move there the existing MSBuild activity

 

Now here is the content of the If block:

clip_image004

And the VB6 activity parameters:

image

 

Check-in the whole thing and check it compiles on a single solution.

Cleaning projects

In order to support the partial clean of builds (Clean Workspace is set to Output), we have to filter the VB6 projects from the process. VB6 executables are produced directly in the BinariesFolder, which is emptied automatically. The following actions will prevent nasty errors when cleaning outputs (because our .vbp aren’t MSBuild files).

First, navigate to Run On Agent => Initialize Workspace, look for the “Clean Project” Sequence, then encapsulate the If File.Exists(Project) with the same filter as we did previously:

 

clip_image007

The full condition text is:

Not localBuildProjectItem.EndsWith(".vbp", StringComparison.InvariantCultureIgnoreCase) And Not localBuildProjectItem.EndsWith(".vbg", StringComparison.InvariantCultureIgnoreCase)

 

Finally, set the process parameter Solution Specific Build Outputs to True to avoid a big mess in the Drop folder. And voilà, you can now mix and build regular solutions or VB6 projects with the same build definition! Smile

clip_image008

Above is what I obtain in the Drop folder, enjoy your builds!

Leave a Reply

Your email address will not be published. Required fields are marked *