Archive

Archive for the ‘Team Build’ Category

Fix TFS 2015 Build’s Queue is Empty


Today I wasn’t able to select a queue while creating a build definition or queuing a build using the new build engine that comes with TFS 2015. The drop down was blank.

This problem may occur if you don’t have build queues for your Collection or if you don’t have permission to use the queues in your build definition.

Go to the administration site for your collection

Check if you have queues for Collection

If you do, select your queueà Role à Agent Queue Users à Double click on Agent Queue Users à add users or groups

Otherwise click the “New queue” link to create a new queue

Scale out Team Foundation Service Build Server

December 13, 2012 1 comment

Overview

Some Visual Studio projects hosted on tfs.VisualStudio.com (formally known as tfsPreview) require specific build environment or the installation of extra components for the build to succeed. For instance, building Windows store projects requires the build server machine to have Windows 8 operating system and Visual Studio to be installed, building a BizTalk project requires the BizTalk SDK to be installed on the build servers, building Lightswitch applications with extensions requires Visual Studio and the extensions to be installed on the build servers and the list goes on.

In this article, I will setup an on premise Build Server to build Windows Store applications that are hosted in tfs.VisualStudio.com. This article assumes you already have an account with tfs.VisualStudio.com and already have a physical machine or VM with Windows 8 as an operating system and Visual Studio 2012 Express for Windows 8 or higher.

Problem

In this article, I have a Windows Store application named “MyWindowsStoreApplication” which is checked in to tfs.VisualStudio.com. Building the MyWindowsStoreApplication using the “Hosted Build Controller” and agent will fail to build as shown in the following figure

image

The TFS Build fails with the error indicating that Windows 8 operating system is required to package the built Windows Store application.

Solution

The solution for the problem is to scale out TFS Server’s Build capabilities and host a TFS Build Controller and Build Agent on a computer or VM that has Windows 8 as an operating system.

Prerequisites

The system requirements to build Windows Store applications are:

  • Windows 8 Operating System
  • Visual Studio 2012 for Windows 8 or higher

Installing TFS Controller and Build Agents

In the following section we will go through the steps needed to create a TFS Build Controller and Build Agents on a local server for the tfs.VisualStudio.com source code repository.

image

The assumption is that you already have a physical machine or VM that has a Windows 8 operating system and Visual Studio 2012 installed.

The following are the step by step instructions to scale out Tfs.VisualStudio.com build server:

  • Insert the TFS2012 DVD or extract the iso file
  • Execute tfs_server.exe on the root folder, if you are using TFS Express, you need to execute tfs_express.exe

image

  • Accept the license terms for Team Foundation Server
  • Click the Install Now button

image

  • When the installation is complete, the Team Foundation Server Configuration Center is launched
  • Select the Configure Team Foundation Build Service from the list
  • Click the Start Wizard button

image

  • Click Next in the Build Service Configuration Wizard to move from the Welcome screen to the Project Collection screen

image

  • Click on the Browse button on the Project Collection screen
  • Click the Servers button on the Connect to Team Project Collection dialog
  • Click the Add button on the Add/Remove Team Foundation Server Dialog
  • Type the name or URL of your team foundation server and select the HTTPS protocol
  • Click the OK button

image

  • Once the OK button is clicked, the Sign in to Team Foundation Server window will be launched
  • Enter your tfs.VisualStudio.com email address and password
  • Click the Sign in button

image

  • Your Team Foundation Server should show up in the Connect to Team Project Collection dialog
  • Click the Connect button

image

  • Now we are back to the Build Service Configuration Wizard, in my case, I haven’t configured on premise TFS build controllers or agent before. Hence, I am getting the Found 0 build controllers and 0 build agents message
  • Click the next button image
  • On the Build Services screen, select Use the default setting. For illustration purposes, I kept the number of build agents to 2. The number of build agents allows to run multiple builds concurrently
  • Click the Next button

image

  • On the Settings screen, the default option is Use a system account option is selected. The Local Service account is selected by default if the machine is not part of a domain. Network Service account is selected by default if the machine is part of a domain
  • Click the Next button

image

Review the settings and click the Verify button to verify the settings

image

Click the Configure button

image

If the configuration is complete successfully, click on the Next button and then close the Team Foundation Build Service Configuration window

image

image

  • Back at the Team Foundation Server Configuration Center, you should see a green check mark which indicates that the service is configured
  • Close the dialog if you don’t want to configure other sections

image

  • Open the Team Foundation Server Administration Console
  • Click on the Build Configuration node
  • Notice that the controller and the Agents are in a healthy state and enabled (green icon). A red error icon would show up instead in the case the controller or the agents are disabled

image

Modify Build Definition

  • Open Visual Studio on your development machine
  • Open Team Explorer window
  • Click on the Build link

image

  • Right click on the build definition that builds your Windows Store application
  • Click on Edit Build Definition

image

  • Click on the Build Defaults tab
  • From the Build controller combo box select the build controller created in the previous section

image

  • Click Save
  • On the Team Explorer window, right click on the build definition
  • Click on Queue New Build

image

  • The build should pass if you don’t have any build errors

image

TFS2010 Add New Argument/Parameter to a Build Template


This post was created in response to this forum question on msdn:

http://social.msdn.microsoft.com/Forums/en-US/tfsbuild/thread/91619304-93df-4635-ba89-7c16f477b852

It is fairly simple to add a new argument to your build template

Click on the Arguments tab

Scroll all the way down and click “Create Argument”

Type the name of your argument (e.g. BuildEnvironment)

To make the argument required, to customize its category, or use a customized editor, we need to create a new parameter in Metadata property as shown in the following image

In the team definition, I added Switch activity (can be added where you want to use that argument) and changed the expression to BuildEnvironment.ToLower to make it case insensitive. Switch activity can be replaced with If activity if the argument can be set to only two values

Click on “Add new case”, type case value to be “dev” or whatever value you need.

Repeat the above steps for other environments (i.e. QA, Prod,..etc)

Click “Add an activity” next to the case statement (e.g. dev)

Drop an activity where it says “Drop activity here”, you can use an Assign activity from the primitive group to initialize certain path

When done, check in the template

Create a new build definition

Under the Process tab, choose your customized template

Notice that you can see your new argument as a parameter

Categories: Team Build, TFS, TFS2010 Tags: , ,

Customize Binaries Folder in TFS Team Build Part-2


In this post I will go through a different way to accomplish what I posted in Part-1. Actually this approach is way simpler and less error prone than the first one.

I will create a new configuration named TFS, change the output path for each project for that configuration to  SolutionPath\bin\Projectname, Create a team build project and update Team build template.

Create a New Configuration

We want to create a new configuration for TFS team build and we don’t want to change the Release or Debug configurations. To do so

  • Right click on the solution
  • Click configuration manager menu

  • From the “Active solution configuration” drop down select <New…>

  • Type TFS in the name textbox
  • Select the configuration to copy configuration from (e.g. Release, or debug)
  • Click OK

  • In the Solution configuration, I am changing the Active Solution Platform to Mixed Platform because the projects in the solutions are targeting different platforms

  • Click Close

Preparing the Projects in the Solution

The following steps will change the output path from bin folder to SolutionPath\bin. I my solution I had a webApplication and a windowsApplication

  • Make sure that the TFS Configuration is selected
  • Change the Output location for each project on the solution to ..\bin\ProjectName.
    • Right click on the projectà properties
    • Click the build tab
    • Fill the “output path” textbox with ..\bin\ProjectName

  • Build the solution to make sure it is working

  • Check in the solution

Create a new Team Build

  • Open Team Explorer
  • Right click on the Builds node
  • Create a new Build, I named it CustomizeBinariesFolder
  • In the Process Tab
  • Expand Items to build
  • Select the solution we configured above
  • Expand Items to build
  • Click the ellipsis next Configurations to Build

  • Type TFS under Configuration and the Platform of that configuration
  • Fill the other fields as you want

Create new Team Build Template

  • Edit your Team Build Definition
  • Go to the process tab
  • Under Build Process Template click the New… button
  • Select an existing template that you want to copy, I am selecting the DefaultTemplate
  • Name the new File
  • Click OK

  • Save the definition
  • Open Source Control from Team Explorer
  • Get latest from BuildProcessTemplates

  • Open CustomizeFolderTemplate.xaml
  • Find “Run MSBuild for Project” Activity under “Try to Compile the Project” block.
  • Clear the OutDir property

  • OutDir property over writes the default output path on each project. By Clearing the OutDir property for the MsBuild Activity, Team build will use the Output Path defined in the project. In my case, C:\Builds\{AgentNumber}\Lajak\CustomizedBinariesFolder\Sources\WindowsFormsApplication1\bin
  • Now we want to copy the contents of the bin folder from the above path (i.e. solutionPath\bin) to the binaries folder
  • Add Copy Directory Activity under Run MsBuild for Project

  • Change the Source Property to IO.Path.Combine(IO.Path.GetDirectoryName(localProject), “bin”), which means, Path of solution file + “\” + bin. By using the combine method we don’t have to worry about the Locale of the machine
  • Change the Destination property to BinariesDirectory
  • Save the Template
  • Go to Source Control Explorer and Check in the Template
  • Run the Team build definition that uses the template you have just modified. I am building the CustomizedBinariesFolder Definition


Customize Binaries folder in TFS Team Build Part 1


A new approach is posted here

Requirements

  • Output binaries must have the following structure

    –Binaries folder

    —-(Build configuration)

    ——–(Project name)

    ————-Binaries files

Issues

The default build template has few limitations that required some customization to meet our requirements. The following are the limitations found:

  • The workflow treats a solution as single project
  • The output of building projects in a solution doesn’t follow the same output directory structure when building in visual studio. For instances, web applications output binaries in the Bin folder while ClassLibrary and Windows applications projects output binaries into the Bin\(configuration) folder.
  • In visual studio, binaries are copied to a bin/(configuration) folder where “configuration” is the configuration of the build (e.g. debug, release..etc) whereas the team build outputs all binaries into one folder called Binaries and that folder doesn’t contain sub folders per project

Solution

I know of two ways to customize the binaries folder. First solution is to modify build template to:

  • Create a folder per project in the solution in the output folder
  • Copy the binaries from the bin folder of each project

Second solution:

  • Modify each project in the solution to output binaries into a common bin folder e.g $(SolutionDirectory)\Bin\$(Configuration)\$(ProjectName)
  • Team build to copy the contents of the bin folder to the binaries folder

This article is a walkthrough for solution 1. I will blog about the second solution in a different post

Modification to Projects

Assume we have the following projects in a solution:

  • Make the Output path for all projects to be the same for all configurations (e.g. debug, release …etc)

Creating new Team Build Workflow Definition

  • Create new Teambuild definition
  • Fill the necessary fields
  • Click on Process on the left
  • Show Details
  • Click the New button
  • Click browse next to “Select the file to copy”
  • Select the Default Template
  • Give it a name

  • Click OK
  • Fill the other fields you need. Make sure you select a configuration for the solution you are selecting
  • Save the build template
  • Browse to the BuildProcessTemplates folder
  • Get latest version of the template we just created

Changes to the Default Template to Meet the Requirements

  • Open the CustomBinariesFolderTemplate.xaml workflow xaml file created in the previous section
  • Click Collapse All

  • Expand On Agent

  • Expand the follow activities:
    • Try Compile, Test, and Associate Changesets and Work Items
    • Sequence
    • Compile, Test, and Associate Changesets and Work Items
    • Try Compile and Test
    • Compile and Test
    • For Each Configuration in BuildSettings.PlatformConfigurations
    • Compile and Test for Configuration
    • If BuildSettings.HasProjectsToBuild
    • For Each Project in BuildSettings.ProjectsToBuild
    • Try to Compile the Project
    • Compile the Project
  • Select MSBuild Activity
  • Set the OutDir property to “”

  • Remember we want to output the binaries into the Binaries folder\Configuration\projectFolder\
  • Add a CreateDirectory Activity under “RunMsBuild for Project”
  • Set the DisplayName property
  • Set the Directory property to

    IO.Path.Combine(BinariesDirectory, platformConfiguration.Configuration)

  • Add FindMatchingFiles activity

  • Set the MatchPatter property to IO.Path.Combine(IO.Path.GetDirectoryName(localProject),“**\*.csproj”). If you want to files of different types you need to use the following syntax:

    IO.Path.Combine(IO.Path.GetDirectoryName(localProject), “**\*.vbproj”) & “;” & IO.Path.Combine(IO.Path.GetDirectoryName(localProject), “**\*.csproj”)

  • Set the Results property to VSProjects. Notice that you will get the Error icon because VSProjects doesn’t exist. Make sure you have the Find Project files activity selected when you are adding the variable to make sure the variable is created in the appropriate scope
  • Create a new variable called VSProjects of type IEnumarable<string> ie IEnumarable(Of String)

  • Add ForEach<String> project found activity, a loop to create a folder in the binaries directory for each project found and then copy the contents of the bin/configuration or bin folder to that created folder below the binaries folder

  • Add a Create directory activity with the following code in the Directory property

    Path.Combine(BinariesDirectory, platformConfiguration.Configuration, Path.GetFileNameWithoutExtension(item))

  • Add a copy directory activity

  • Change the destination and the source properties to copy the files in the bin folder of in the source folder to the Binaries\project folder\ directory

  • Save the work flow build template and check in the template

  • Queue a build
  • When build is complete go to the binaries folder and notice that you have three folders, one per project.

Categories: Team Build, TFS, TFS2010 Tags: , ,

TFS 2010: MSBUILD : error MSB1008: Only one project can be specified


You may get the following error during the team build

MSBUILD : error MSB1008: Only one project can be specified. Switch: CPU /p:VCBuildOverride=C:\Builds\1\Lajak\SilverlightApplication3\Sources\SilverlightApplication3.sln.Any For switch syntax, type “MSBuild /help”

TF270015: ‘MSBuild.exe’ returned an unexpected exit code. Expected ‘0’; actual ‘1’.

Solution

Make sure that none of the MSBuild switches contain a space and switches are surrounded with double quotes. If any of the switches contain a path that contains a space, make sure that it ends with double backward slashes. You can also remove the backward slashes at the end.

Example:

/p:referencepath=”$(SourceDirectory)\Referenced Assemblies\lib\\”

Categories: Team Build, TFS, TFS2010 Tags: , ,

Pass Relative Path Arguments to MSBuild in TFS2010 Team Build


If you are familiar with the Team Build process in TFS2010, you can skip the background section.

Background

As we know that in TFS2010, the team build leverages workflow instead of build scripts. We will also notice that TFSbuild.proj no longer exists. We can find the build template at the BuildProcessesFolder Open the DefaultTemplate.xaml, and expand the workflow. Then find the MSBuild activity Hit F4 or open the Properties Window. Notice the CommandLineArguments property. The value of that property is passed to MSBuild process as argument (i.e. MSbuild.exe /p:SkipInvalidConfigurations= true /p:referencepath=somepath …. Notice the MSBuildArguments in the value field. The MSBuildArguments is an Argument that is built into the Default Team Build template. If you click the Arguments button at the bottom, you will find it listed there. Those arguments are properties in your team build definition. Right click on the team build definition, click Edit Build definition

Select the Process tab from the left tab list. Notice that the Build process parameters are listed in the arguments list in the build template. Keep in mind, only the arguments with the “In” or “In/out” direction are visible to the process template

 

In a solution that contains many projects, it is normal to have a folder that contains common references to third party assemblies. Those assemblies can be custom controls, enterprise libraries, reusable libraries from other projects, ..etc. The Msbuild needs to have a reference to that folder to be able to compile the project or the solution. You need to keep in mind the following points:

  • Team build downloads the latest files from source control every time team build is requested; custom assemblies need to be checked in
  • The folder need to be visible to the teambuild workspace; in build definitionworkspace
  • Typically you have multiple build agents whose working directory path is different from the development workstation and other build agents. In other words, you can’t pass an absolute path to msbuild

Problem

We want to pass a relative path as MSBuild argument i.e. MSBuild /p:referencepath=”$(SourceDirectory)\referenced assemblies\”. Team build template doesn’t out of the box convert $(SourceDirectory) to a physical path when passed as MsBuild argument

Solution

We need to modify the build template to replace $(SourceDirectory) with the source directory’s physical path.

  • Add an If activity to check if the MSBuildArguments is null or empty. To keep things organized, I recommend adding the activity to the “Run on Agent”Initialize Variables. Make sure you add it at the end because the source directory is initialized in that block
  • Add an Assign Activity to the Then block.

  • Open the properties window
  • Give the activity a more descriptive name
  • In the To property, type MSBuildArguments
  • In the value property, type MSBuildArguments.Replace(“$(SourceDirectory)”, SourcesDirectory). This is case sensitive.

  • Save the template
  • Check in the template

  • Open an existing build definition or create a new one
  • Go to the process section
  • Expand the advanced section
  • Enter /p:referencepath=”$(SourceDirectory)\Referenced Assemblies\\” in the MsBuild Arguments parameter, where “Referenced Assemblies” is the folder where your assemblies are saved. Don’t forget the quotes and the double slash that the end (i.e. \\). Thanks to  Bernd who commented on the this post. I was able to confirm if you have spaces in your path you need to either add double slash at the end of the path or no slash characters at all (e.g. “$(SourceDirectory)\Referenced Assemblies”)

  • Save the definition and queue a new build
  • The following is a screen show of the log