How to set the “default” configuration for a project.

Being a Process Consultant specializing in TFS I teach many companies how to use Team Build.  When you create a new build definition you have the option to set “Configurations to Build”. However, if you leave that value blank the build will build the “default” configuration. The questions I am inevitability ask are “what is the default configuration” and “how do we set the default configuration”?  Well in this post I will show you where it is stored and how to update it for typical Visual Studio 2012 project. Visual Studio projects are msbuild scripts and because of that we can set properties in the actual project files that are going to be sent to msbuild to be compiled.  To change the default configuration you we need to load the project file as xml which is the file format of msbuild.  With the project open in Visual Studio simply right click on the desired project and select “Unload Project” from the context menu.  Once the project is unloaded right click on it again and select “Edit [Project Name]” and Visual Studio will open the file as an xml file we can edit.  Search the file for a “Configuration” element in a property group (it is normally the first group).  It should look similar to this: <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>   This is the line responsible for setting the default configuration of your build.  Simply change “Debug” to the desired default configuration, save the file then right click on project file in Solution Explorer and select “Reload Project”.  After you check in your changes an queue a new build it will be built using this configuration if the “Configurations to Build” is blank in the build definition.

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

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)

All my workspaces are missing!

Normal 0 false false false EN-US X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;} 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.

Build workspace folder already mapped.

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]]

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

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 Agent2.    Try Compile, Test, and Associate Changesets and Work Items 3.    Sequence4.    Compile, Test, and Associate Changesets and Work Items5.    Try Compile and Test6.    Compile and Test7.    For Each Configuration in BuildSettings.PlatformConfigurations8.    Compile and Test for Configuration9.    If BuildSettings.HasProjectsToBuild10.    For Each Project in BuildSettings.ProjectsToBuild11.    Try to Compile the Project12.    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)

My build agent just stopped working!

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 Options2. Choose the Connections tab3. Click the “LAN settings” button4. 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.

Can't save values in custom controls on TSWA 2010

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.