I have to create the same branches in every new team project

by Donovan Brown 17. December 2012 23:48

Problem:

I have to create the same branching structure in several team projects.  I would like a way to automate this process.

Solution:

Use the tf.exe and tfpt.exe command line tools in a batch file.

Explanation:

Using the tf.exe and tfpt.exe command line tools you can preform the same task from the command line that you can preform in the IDE.  Using tf.exe and tfpt.exe we can script the creation of the desired branching structure to speed up the process.

You can download the Microsoft Visual Studio Team Foundation Server 2012 Update 1 Power Tools from here.

The script below creates the Basic Branch Plan from the Visual Studio Team Foundation Server Branching and Merging Guide which you can download from here.

The script must by run from a Developer Command Prompt so that tf.exe and tfpt.exe can be found.  Your other option is to update the environment variables for you machine to include the location of tf.exe and tfpt.exe in your path.

@ECHO OFF

REM If they did not provide arguments show them how to 
REM use this batch file
if "%1" == "" GOTO Usage
if "%2" == "" GOTO Usage

REM Create a temp workspace to create the branches in.
REM This will be deleted at the end
tf workspace /new /noprompt temp /collection:%1

REM Before you can create branches you must do a get latest
tf get $/%2

REM Create a main folder that will become the main branch of code
md %2\Main

REM Add this folder to TFS
tf add %2\Main /noprompt

REM Check in the main folder
tf checkin /comment:"Adding main branch" /recursive /noprompt

REM Now start creating the other branches
REM main to dev
tf branch $/%2/Main $/%2/Dev /noget /checkin

REM main to release
tf branch $/%2/Main $/%2/Release /noget /checkin

REM We have to use tfpt from the power tools to convert
REM the folder to a branch so we get the new branch icons
REM in source control explorer
tfpt branches /convertToBranch /collection:%1 /recursive $/%2/Main

Echo Deleting temp workspace
Echo.
tf workspace /delete /noprompt temp

REM Remove the directories we created
rd %2 /s /q

REM Skip usage and just end
GOTO End

REM Show how to use the script
:Usage

Echo This batch file will create the default Main, Dev and Release branches
Echo for a team project.
Echo Requires:
Echo Microsoft Visual Studio Team Foundation Server 2012 Update 1 Power Tools
Echo.

Echo Usage:
Echo   createBraches collection teamProjectName
Echo.
Echo     collection = http://tfs:8080/tfs/myCollection
Echo     teamProjectName = the team project name in that collection 
Echo.
Echo   createBranches http://tfs:8080/tfs/sandboxcollection teamProjectName

:End

createBranches.cmd (1.67 kb)

Tags: , , , , ,

Work

All my workspaces are missing!

by Donovan Brown 25. August 2012 01:10

Problem:

After a TFS server move all my workspaces are missing.

Solution:

Use the TF.exe Workspace command with the /newowner option.

Explanation:

During a recent TFS upgrade and migration from TFS 2010 running in workgroup mode to TFS 2012 on a new server I lost all my workspaces.  From the new TFS server I could run the TF.exe workspaces command and see all the existing workspaces.  However, if I were to open Visual Studio on any of the client machines none of those workspaces would show up.

When TFS is in workgroup mode user accounts are all local accounts.  On the TFS server there was for example a Donovan L Brown account.  The name would be in the format of ComputerName\UserName.  After I moved to new hardware the computer name was different.  However, all the workspaces were owned by the accounts with the old computer name.  You can confirm that by running the TF.exe workspaces command and looking at the owner column.

My goal is to simply update the owner of the workspace to point at the new local Donovan L Brown account on the new computer. 

tf workspace [/collection:TeamProjectCollectionUrl] [workspacename[;workspaceowner]] [/newowner:ownername]

If you have pending changes in the workspaces you will have to shelve them first.  This can be a bit of a challenge as well because you are not the owner of the workspace yet.  To work around this just use the TF.exe workspace command to change the workspace to public.  After which you can shelve the changes using your new account.  Once the changes are shelved you can change the workspace owner to the new account. Finally you can unshelve your changes and return to work.

Tags: , , , ,

Work

How to fail a TFS2010 Build from workflow

by Donovan Brown 4. October 2011 18:37

Problem:

I have tried setting the BuildDetail.CompilationStatus and BuildDetail.Status but my build keeps Partially Succeeding.

Solution:

Use the SetBuildProperties activity to set the status to fail.

Tags: , , ,

Work

Build workspace folder already mapped.

by Donovan Brown 4. October 2011 04:03

Problem:

My Team Build keeps failing with an error that my source folder is already mapped in another workspace. The path C:\Builds\1\Demo\Reports\Sources is already mapped in workspace 7_1_WIN-GS9GMUJITS8.

Solution:

Use the tf.exe tool to delete the workspace holding on to that location.

Explanation:

tf workspace /delete [/collection:TeamProjectCollectionUrl] workspacename[;workspaceowner] [/login:username,[password]]

Tags: , ,

Work

I need to build a project that is not supported by MSBuild

by Donovan Brown 16. July 2011 00:48

Problem

My solution contains a .vdproj and it is not supported by MSBuild.

Solution

Call devenv from team build using InvokeProcess for .vdproj projects.

Explanation

This customization can be extended to build any project types not supported by MSBuild (vb6, power builder, fortran, VC++ 6, etc).  Any project that can be built from the command line can also be built using TFS 2010 Build using this technique.

We are simply going to add a switch statement that uses the extension of the project to determine if we pass it to MSBuild or perform the build ourselves.  Let’s start by opening DefaultTemplate.xaml from the BuildProcessTemplates folder.  To begin we must locate the correct area of the build template to add our switch statement.  I find the quickest way to do this is to click the Collapse All button at the top of the workflow designer window.  Now double click on the words Double-click to vew on all of the following activities:

1.    Run On Agent
2.    Try Compile, Test, and Associate Changesets and Work Items
3.    Sequence
4.    Compile, Test, and Associate Changesets and Work Items
5.    Try Compile and Test
6.    Compile and Test
7.    For Each Configuration in BuildSettings.PlatformConfigurations
8.    Compile and Test for Configuration
9.    If BuildSettings.HasProjectsToBuild
10.    For Each Project in BuildSettings.ProjectsToBuild
11.    Try to Compile the Project
12.    Compile the Project


The Compile the Project Sequence contains the Convert Server Path to Local Path and Run MSBuild for Project activities.  We are going to add our switch around Run MSBuild for Project.  In the toolbox expand the Control Flow tab and drag and drop the Switch<T> activity right above the Run MSBuild for Project activity.  When prompted for type, select String and click OK.

Our switch is going to test the extension of the current project being built. If the extension is .vdproj we are going to call devenv ourselves to build the setup project.  If the extension is anything else we are going to simply let MSBuild build it.  So the first thing we need to do is find the extension of the project being built.  The Convert Server Path to Local Path activity stores the project path in localProject which we can use to find the extension.  Click the double down arrows in the title bar of the Switch<String> activity to show the expression and cases of the switch.  In the Expression text box enter the following:

(New System.IO.FileInfo(localProject)).Extension.ToLower()

This line of code uses an instance of the FileInfo class to gain access to the extension of the current project being built.  We call ToLower to make sure the case of the extension is known for our comparison.

Now click the word Default to display the activity area of that case.  Drag the Run MSBuild for Project into the default case.

At this point the template works exactly as it did before we touched it. After our customizations you will still be able use this template for all your current builds that use the default template.

Now it is time to add the case for the .vdproj projects. Click the words Add new case. In the Case Value combo box type .vdproj without ”’s.  The switch already knows that what you are going to type is a string so you DONOT type the “’s.  If you do it will fail because “.vdproj” is not equal to .vdproj.

From the toolbox drag and drop a Sequence activity from the Control Flow tab onto the .vdproj case.  Change the display of this sequence to Build Setup Project.  We add a sequence here so that we can use multiple activities. Click the double down arrows in the title bar of the sequence to show it's contents.  This is where we are going to add the activities needed to build the setup projects.

Before we can add the InvokeProcess activity to build the setup projects we first need to know the command line.  Below is an example of the command line to build a setup project.  Notice we must provide the configuration to build

"C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\devenv" "C:\Builds\1\Build Sandbox\HelloWorld\Sources\HelloWorld\Setup\Setup.vdproj" /build Release

Now we can add the InvokeProcess activity and set the properties to build this command line during the build.  To get started simply drag and drop the InvokeProcess activity from the Team Foundation Build Activities tab into the Build Setup Project sequence.  With the InvokeProcess activity selected set the following values in the properties window:

•    Arguments - """" + localProject + """ /build " + platformConfiguration.Configuration
•    FileName - """C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\devenv"""

The rest of the values can remain with their default values.  Pay close attention to the number of “’s and white space.  Because localProject may contain spaces we must quote the string. The same is true for the path to devenv.exe.

 
Whenever I use an InvokeProcess activity I always expand it and add a WriteBuildMessage under Handle Standard Output with the Message set to stdOutput and a WriteBuildError under Handle Error Output with the Message set to errOutput.  This will allow that information to be show in the build output.

 
At this point if we check in our changes and add our .vdproj file as an Items to Build from the Process tab of the build definition the setup project will be built.  Be sure and remove the .vdproj project from the solution or you will continue to get errors from MSBuild.

However, it will not be in our drop location.  The reason for this is because only items that are in the binaries folder get copied to the drop location.  The final piece is to add a CopyDirectory activity under the InvokeProcess to copy the contents of the output folder of the setup project to the binaries folder. With the CopyDirectory activity selected set the following values in the properties window:

•    Destination - BinariesDirectory
•    Source - (New System.IO.FileInfo(localProject)).DirectoryName + "\" + platformConfiguration.Configuration + "\"

Your Build Setup Project sequence should look like this:

 
Now save your xaml file, check in your changes and queue a new build.

You can download a copy of the final file below.

TFS2010 DefaultTemplate.xaml (59.14 kb)

TFS2012 DefaultTemplate.11.1.xaml (81.14 kb)

Tags: , , , , ,

Work

My build agent just stopped working!

by Donovan Brown 20. June 2011 18:11

Problem

My build agent state in Team Foundation Administrative Console states Ready but the icon shows stopped and I can't queue builds.

Solution

Either log in as the Service Account used to run the build agent or log in using any account and right click on IE and run as the Service Account.
1. Open Internet Explorer and go to Tools –> Internet Options
2. Choose the Connections tab
3. Click the “LAN settings” button
4. Uncheck the “Use a proxy server for your LAN” checkbox. 

Explanation

One of my builds collects code coverage results on a web application.  To do so the IE connection settings are configured to use a proxy while the data is collected and then returned to the original configuration afterwards.  However, if you are forced to stop a build the proxy will stay configured and lead to this problem. The key is to log in or run IE as the Service account to uncheck the proxy check box on the connection setting of IE.

Tags: ,

Work

I need to attach files larger than 4KB to my work items in TFS 2010

by Donovan Brown 20. May 2011 17:50

Problem

I need to attach files to work items that are larger than 4KB on TFS 2010.

Solution

Use the web services on the Application Tier to increase the attachment size.

Explanation

The default value of work item attachments is 4KB.  However, that limit can be adjusted up to 2GB if required.  To update the value you must be a TFS Admin and on the TFS Application tier to perform this process.

Open IIS Manager and expand <Server>\Sites\Team Foundation Server\tfs\_tfs_resources\WorkItemTracking\v1.0If using Server 2008 switch to Content View to see the webservices.  Right click on ConfigurationSettingsService.asmx and select Browse.

The trick to making this work is to replace “_tfs_resources” with the collection name. 

After you replace “_tfs_resources” with your collection name press Enter to reload the page.  Now you can use the SetMaxAttachmentSize method to increase the file size.

Tags: , , ,

Work

How to customize the available Build Qualities in TFS2010

by Donovan Brown 26. September 2010 04:00

Problem:

The default build qualities provided by TFS2010 do not match our current process for build promotion.

Solution:

Customize the list of available build qualities in TFS2010.

Explanation:

From the Team Explorer window you can right click on the builds folder and select Manage Build Qualities from the context menu.

Tags: ,

Work

Can't save values in custom controls on TSWA 2010

by Donovan Brown 27. August 2010 17:57

Problem:

I just upgraded my TFS 2008 to 2010 and my custom TSWA controls are no longer saving values.

Solution:

Make sure the first thing you do in the InitializeControl() method from the IWebWorkItemControl inteface is call the code that populates the base.Controls collection.  For example to get the MultiValue control to work you must add a call to EnsureInnerControls() as the first line in InitializeControl() otherwise the values will not save.

Tags: ,

Work

Where in the world is WorkItemChangedEvent defined?

by Donovan Brown 25. August 2010 18:05

Problem:

I am not asked to write TFS Event Handler web services very often and I can never remember where WorkItemChangedEvent is defined.  I spend more time searching for that missing reference than I do writing the code.

Solution:

For TFS 2010 WorkItemChangedEvent is in C:\Program Files\Microsoft Team Foundation Server 2010\Tools\Plugins\Microsoft.TeamFoundation.WorkItemTracking.Server.Dataaccesslayer.dll.

Tags: ,

Work

About the author

My name is Donovan Brown and I am a process consultant for Imaginet with a background in application development.  I also run one of the Nation’s fastest growing online registration sites for motorsports events DLBRacing.com.  When I am not writing software I race cars for fun.  DLBRacing.com has given me the opportunity to combine my two passions writing software and racing cars.

AdSense

Month List

AdSense