Posts Tagged ‘Team Explorer’

TFS2012: Create Build Definitions


In this article I will explain how to create a build definition in the Visual Studio 2012 and TFS 2012 server. I used TFS 2012 Express when I wrote this post. In a previous post, I went through the build types that Team Foundation Server supports.

To run a Team Build in TFS, assuming you already setup the Build Controller and Agents, you need to create a build definition. A build definition acts as a settings or configurations file for the build process.

Create Build Definition

The following steps show how to create a team build definition:

Open Visual Studio 2012

Open Team Explorer (View—>Team Explorer)

Connect to a TFS Server and Team Project


After you are connected to the Team Project of interest, go back to the Home menu or page and click on the Builds link


Click New Build Definition to create a new build definition


Give your build definition a meaningful name (e.g. mypp-CI-Debug, myapp-Scheduled-UnitTests).

Queuing process option is sufficiently explained on the screen.


Click on the Trigger node

On this screen, you can specify the build type. Build types were covered in the previous article. Under Rolling builds, Build no more often than ever x minutes means you want at least x minutes between builds to allow for build accumulation. Under Gated Check-in, check the Merge and build up to x submissions, if you want to group submissions when building them to improve performance.


The next step is to configure the Workspace.

On this screen, you can select as many folders as you want. Those folders and their contents will be downloaded (Get performed) to the Source Directory to the code. As a best practice, you want to avoid referencing the root folder of you team project (e.g. $/MyTeamProject) because you want to avoid getting the code for unrelated files or projects. Point to the folder where your code exists and add other folders for other related code or libraries such as libraries for third party controls. When adding multiple folders, make sure you maintain the folder level or relative path among folders at the Build Agent Folder.


Click on the Build defaults, it is probably called with that name because you can override these values when you queue a build <— I am guessing 🙂

On this screen, you have to specify a Build a controller and the drop folder location. The drop folder contains the output of the build process.


The Process screen is where you can define the Build process Template, which is a workflow of activities to execute your team build, and the Build process parameters that are passed to the workflow build template as arguments.


If you are using the Default Template, you need to at least populate the Items to Build parameter with a solution. Deferent build templates may have deferent parameters. You can also create and customize a build template.

Click the ellipsis button

Click on Add

Select a solution

You can select multiple solutions

You can set the configurations for the build in the Configurations tab


In another post, I will explain the other parameters.

The last step, is to define the retention policy. The retention policy automate the deletion of old builds to save disk space.

Save the build definition

Notice that it will be added to the build definition section on the build window. To queue a build manually, right click and click on Queue New Build


TFS2012: Schedule a One Time Team Build–Approach 1

In response to the questions asked on MSDN social, I am writing this blog post. The question was “How to schedule a one off build”. I also posted an alternative approach here


When creating a scheduled build, you need to specify the the day of week and time.


But what if you only want to schedule it to run once? That scenario is not supported by TFS out of the box.


One of the solutions I am proposing in this post is to create a scheduled build definition and a custom activity to reset the build definition trigger to manual when the build is complete. The limitation for this approach is you can’t specify a date (e.g. 22/1/2013). In other words, you can only schedule it for the next 7 days.

I am using TFS2012 and Visual Studio 2012 for this solution. You can still use the same steps for TFS 2010.

Creating Build Activity

Create new project of type Activity Library and name it TeamBuildActivities


Delete Activity1.xaml


Add new item of type Code Activity and name it SetTeamBuildDefinitionTriggerToManual



Add a reference to C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Build.Client.dll

Paste the following code in the SetTeamBuildDefinitionTriggerToManual .cs file

using System.Activities;
using System.ComponentModel;
using Microsoft.TeamFoundation.Build.Client;

namespace TeamBuildActivities
public sealed class SetTeamBuildDefinitionTriggerToManual : CodeActivity

public InArgument<IBuildDetail> BuildDetail { get; set; }

// If your activity returns a value, derive from CodeActivity<TResult>
// and return the value from the Execute method.
protected override void Execute(CodeActivityContext context)
if (BuildDetail == null)
IBuildDetail buildDetail = context.GetValue(BuildDetail);

if (buildDetail == null)

buildDetail.BuildDefinition.TriggerType = DefinitionTriggerType.None;


Save and build the project

Copy the output assembly TeamBuildActivities.dll to C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\PrivateAssemblies

Create a build definition

Create your build definition with a scheduled trigger


On the process, click show detail and then the new button


You should rename the New file name, I am keeping the default name in this example

Click OK

Open the Source Control Window

Right click on the new build process template and get latest


Double click on the new build process template to open

Open the Toolbox window

Create a new Tab and call it Custom Activities

Right click on the custom activity area and select Choose Items


Make sure that System.Activities Components Tab is selected

Click on the browse button

Go to the C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\PrivateAssemblies folder and select the TeamBuildActivities.dll and click OK


Drag and drop the activity at the end of the workflow


Type in the BuildDetail argument into the BuildDetail property grid


Save workflow template and then check it in


Create new Folder in TFS Source Control for Build Activities

Go to the Source Control Windows

Create new folder, I am naming it TeamBuildAssemblies


Open the local folder and copy TeamBuildActivities.dll to it


Go back to source control

Right click on the folder you created and select Add Items to folder


Select TeamBuildActivities.dll from the window


Check in the folder


Point Controller to the TeamBuildAssemblies

At this point, we want the team build to load the custom activity we created to initiate an  instance of the SetTeamBuildDefinitionTriggerToManual activity

Click on Actions

Then Manage Build Controllers


Click on Properties

Select the path for the TeamBuildAssembles folder


Click OK

Queue a Build

Lets queue a build to simulate the running of a scheduled build

You may get the following error

TF215106: Access denied. NT AUTHORITY\NETWORK SERVICE needs Edit build definition permissions for build definition TeamBuildActivities in team project MyTeamProject to perform the action


To fix the error you need to give  “Edit build definition” permission to the build account

Right click on the team build definition

Select Security


Select Build Service Accounts

Change the value for Edit build definition to allow

SCROLL DOWN AND CLICK SAVE CHANGES. For low resolution screens this may not be so intuitive because the button is hidden


Now queue another build


Edit the build definition and click on the Trigger tab


Notice that it is switched to Manual

Team Explorer: Save Codeplex Username and Password

A friend of mine emailed me few minutes ago saying that it is too annoying that TFS keeps asking him to enter his username and password and asked me if there is a way to save the username and password. The following are the steps to do so:


Using Windows 7:

Open Windows Explorer and go to Control Panel\User Accounts and Family Safety\Credential Manager

Click Add a Windows Credential



Enter in the “Internet or network address” textbox

Enter your username and password. To find out your username check this Post


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.


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


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


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

Team Build: Could not find file ‘Microsoft.BizTalk.TOM.resources’ when running Biztalk Unit tests

February 15, 2011 1 comment

I have set up Team Build to build a solution that contains Biztalk and C# projects. The environment I used was Biztalk 2010 and TFS 2010. When running the unit tests related to Biztalk Schemas or Pipelines I used to receive the following exception:

Could not find file ‘Microsoft.BizTalk.TOM.resources’

I know that I have a reference to the Microsoft.BizTalk.TOM.dll assembly in the Biztalk project and the unit test project. Unit tests were running on Visual studio 2010 but failing on team build.

I figure out that for some reason, Team Build decides not to copy the Microsoft.BizTalk.TOM.dll assembly to the binaries folder of that unit test project although I have the “copy local” property set to true. To force deploying the assembly to the unit test folder, make sure that you add it to the testsetting deploy option. Make sure that Biztalk server is installed on the Teambuild machine and the path for the assembly is valid on the Teambuild server. Otherwise you need to checkin the assembly into source control and reference the assembly in source control. 

  1. Open the testsettings file used for the team build definition
  2. Click Deployment from the list on the left
  3. Click Add Files


How to Find Build Service Account in TFS2010 and Visual Studio 2010

  • Open Visual Studio
  • Open Team Explorer
  • Right click on team project
  • Select Team Project Settings menu item
  • Select Group Membership menu item

  • On the Project Groups on [Team Project Name] dialog, check Show global groups
  • Click Defaultcollection\Project Collection Build Service Account
  • The User or Group list box, lists the build Service Accounts

How to use Team Explorer with Codeplex

I decided to write this post because many including myself found it a bit confusing to connect Team Explorer to Codeplex. I am using Visual Studio 2010 Ultimate Edition.

Create Codeplex User

  1. Click on the Register link
  2. Fill the required fields and hit the Register button

Participating in a Project

To participate in a project on Codeplex, you need to contact the project coordinator. Follow the following steps to find out who the project coordinator is:

  1. Go the project page
  2. Click on the people tab
  3. Click on the coordinator’s link

Connect to Codeplex Project via Team Explorer

Team Explorer is included with Visual Studio 2010 Professional, Premium and Ultimate. Follow the following steps to connect to codeplex using Team Explorer:

  1. Go to the project page on Codeplex. Make sure you are logged in
  2. Click Source Control tab
  3. Click Visual Studio Team Explorer and keep that page open
  4. Open Visual Studio
  5. Click the Team menu. If you can see it, click View –> Team Explorer and click the connect to Team Project button
  6. On the Connect to Team Project dialog
    1. Click Servers button
    2. Click Add button on the Add/Remove Team Foundation Server dialog
    3. Fill the information in the Add Team Foundation Server dialog from Codeplex page in step 4
  7. Enter the Username as you see it in the codeplex page, my username was prefixed with snd\ and suffixed with _cp. I am not sure if all usernames are prefixed and suffixed with the same characters
  8. Click Ok and close the Add/remove TFS dialog
  9. Click the connect button on the Connect to Team Project dialog
  10. Double click the Source Control node
  11. I am mapping the root of the tree to the Codeplex folder on my C directory. You can map yours to what ever directory
  12. Click the Map button
  13. Get latest and you should be good to go 🙂