26Aug

TFS Build for .Net 2.0 Projects

Clients have strange requirements. The other day I had been to a client for a discussion. These guys are using .Net 2.0 framework for their application. What’s strange is that new development is also happening in 2.0 framework.

The problem arose when these guys wanted to use TFS Team build for building their legacy apps written in .Net 2.0. As you guys might be aware, MS Build (part of TFS Build) can be used to build only applications with .Net framework 3.0 and above.

When back in office, did some brainstorming with my colleagues, some searching on the net and decided to invoke the VS 2005 IDE from the build xaml file instead of using MS Build for compiling the project and then copy the binaries from each of the bin folder under the Sources folder to the Binaries folder manually.

An issue I came across even though the applications had compile time errors, my team build showed that it was successful. To fix this issue, I had to use the return value from the invoke process to check if the return value is 1 or 0. VS 2005 returns 0 when it is able to successfully build the application else it return 1. Using this logic I put a conditional check to see if the build was successful, if not I used the "SetBuildProperties" activities and set the status to

"Microsoft.TeamFoundation.Build.Client.BuildStatus.Failed".

Here are the steps which was followed:

  1. Create a new BuildTemplate.xaml file by making a copy of the existing one. Let us call this template as “VS2005BuildTemplate.xaml”.
  2. Open this file in Visual Studio and Locate the “Run MS Build for Project” activity located under Run On Agent -> Try Compile, Test, and Associate Changesets and Work Items -> Compile and Test -> For Each Configuration in BuildSettings.PlatformConfigurations -> Compile and Test for Configuration -> If BuildSettings.HasProjectsToBuild -> Try to Compile the Project -> Compile the Project.
  3. Knock off this activity.
  4. Create a new variable called ReturnValue of type Int32 and scope it to“Compile, Test, and Associate Changesets and Work Items”
  5. Drag n drop the “InvokeProcess” activity from the toolbox. We will use this activity to invoke VS 2005. And set its properties as below:
    1. Arguments: Pass the project name and /build parameter to build the application. In my case I set it to –  """" + localProject + """ /build"

The double quotes are required. Sometimes the project path may contain spaces, in that case the compilation will fail.

  1. FileName: The path where VS 2005 is installed. I set this to –  "C:\Program Files (x86)\Microsoft Visual Studio 8\Common7\IDE\devenv.exe"
  2. Result: After VS 2005 compiles, it returns a value. Use the earlier created variable in Step 4. I set it to – ReturnValue
  1. Refer the below Screen grab:

Invoke Process for Invoking VS 2005 IDE

 

  1. Drop n drop an If activity and set its condition to “ReturnValue = 1”
  2. In the Then section of the If activity drop a SetBuildProperties activity. Set the properties of this activity as below:
    1. PropertiesToSet:  Status
    2. Status: Microsoft.TeamFoundation.Build.Client.BuildStatus.Failed
  3. After doing the above two steps, the If activity should look like below:

If Activity

 

  1. In case we used MS Build for building our application, then it would create a directory called “Binaries” in the Agent workspace. Since we are using VS 2005 IDE to build the application we need to do this manually. Drag n drop a CreateDirectory activity and set the “Directory” property of this to BuildDirectory + "\Binaries".
  2. After the application is built in VS 2005, we are using a post build script to copy the output to a pre-specified folder like in the below screen grab:

 

Project Properties

 

 

  1. So you should have this folder created on your build machine.
  2. To customize this, we can create an argument in the build which can accept this path.  Follow the below steps to achieve this:
    1. Create a new argument called “BinariesPath” with Direction as “In” and Argument Type as “String”
    2. Select the existing Metadata argument and create a new item in the collection by clicking on the Ellipses button as shown in the below screen grab:

   Creating an Argument   

 

  1. After doing this, you should be able to see the “BinariesPath” in the Process tab under a new section called Misc like below:

Argument in the Process Tab

  1. When the newly created build is queued, all the output from that solution/project will be copied to the BinariesPath folder, which in my case is C:\Binaries.
  2. Next we need to copy all the output from the BinariesPath folder to the Binaries folder created in Step 10. For this, simply call the xcopy.exe. Drag n drop another InvokeProcess and set its properties as follows:
    1. Argument: """" + BinariesPath + """ """ + BuildDirectory + "\Binaries"""
    2. FileName: "xcopy.exe"
  3. After doing all this, the xaml file should look something like below:

  Customized Template  

 

  1. Create a new build definition, select the newly created xaml file – VS2005BuildTemplate.xaml in the Process tab; and don’t forget to specify the BinariesPath.
  2. Queue the build, and it should build the VS 2005 project.

 

All the best and Happy Building.wink

Related

How to Prevent Users from Moving Task to Closed State with a non-Zero value Remaining Work field in VSTS/TFS

In this Blog I am going to explain how we can customize Task in VSTS/TFS to Prevent Users from Movin...

Read More >

Dashboard Migrator Tool

This is a web service which helps you to copy the VSTS dashboards from 1 team to another team easing...

Read More >

Canarys Automations Pvt Ltd recognized as finalist for 2017 Microsoft DevOps Partner of the Year Award

  Bengaluru, Karnataka, India — June 2, 2017 — Canarys Automations Pvt Ltd tod...

Read More >

Bugzilla to TFS Migrator (Part 2 of 4) – Installation

This is the second part of the Bugzilla to TFS Migrator blog series covering the installation of the...

Read More >

Bugzilla to TFS Migrator (Part 3 of 4) – Configuration

This is the third part of the Bugzilla to TFS Migrator blog series covering the configuration of the...

Read More >

Bugzilla to TFS Migrator (Part 4 of 4) - Migration

This is the final part of the Bugzilla to TFS Migrator blog series covering the actual steps of migr...

Read More >

TFS 2013 Build Template Customization

How to enable logging verbosity process parameter in build definition?Verbosity for a build will hel...

Read More >

Automating .NET builds using CCNET and TFS

CruiseControl.NET (CCNET) is an open source tool used for continuous builds on server, where testing...

Read More >

Migrating TFS 2013 Version Control to TFS Git with changeset history

There are several articles on the web describing the migration technique with minimal details. This ...

Read More >

Share

Post a Comment

  • Recent
  • Popular
  • Tag
Monthly Archive
Subscribe
Name

Contact Us
  • *
  • *