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:
- Create a new BuildTemplate.xaml file by making a copy of the existing one. Let us call this template as “VS2005BuildTemplate.xaml”.
- 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.
- Knock off this activity.
- Create a new variable called ReturnValue of type Int32 and scope it to“Compile, Test, and Associate Changesets and Work Items”
- Drag n drop the “InvokeProcess” activity from the toolbox. We will use this activity to invoke VS 2005. And set its properties as below:
- 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.
- FileName: The path where VS 2005 is installed. I set this to – “C:Program Files (x86)Microsoft Visual Studio 8Common7IDEdevenv.exe”
- Result: After VS 2005 compiles, it returns a value. Use the earlier created variable in Step 4. I set it to – ReturnValue
- Refer the below Screen grab:
- Drop n drop an If activity and set its condition to “ReturnValue = 1”
- In the Then section of the If activity drop a SetBuildProperties activity. Set the properties of this activity as below:
- PropertiesToSet: Status
- Status: Microsoft.TeamFoundation.Build.Client.BuildStatus.Failed
- After doing the above two steps, the If activity should look like below:
- 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”.
- 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:
- So you should have this folder created on your build machine.
- To customize this, we can create an argument in the build which can accept this path. Follow the below steps to achieve this:
- Create a new argument called “BinariesPath” with Direction as “In” and Argument Type as “String”
- 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:
- After doing this, you should be able to see the “BinariesPath” in the Process tab under a new section called Misc like below:
- 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.
- 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:
- Argument: “””” + BinariesPath + “”” “”” + BuildDirectory + “Binaries”””
- FileName: “xcopy.exe”
- After doing all this, the xaml file should look something like below:
- 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.
- Queue the build, and it should build the VS 2005 project.
All the best and Happy Building.