Create a TFS Build Custom Activity to Read From File

I needed to create a Custom Activity that read from XML file and display the values on the Build log.

It’s very easy and I will not re-write how to do the basic Custom Activity, but if you are not familiar with that, you can see the following link:
Use and develop custom build process activities

Here, I needed to add OutArgument to return the value that I got from reading the file, I will got the value from the file and assign that value to OutArgument.
OutArguemnt in TFS Custom activity

After that, I built the project and distribute the library (DLL) under source control where the build controller point for the custom assemblies, see the previous link for the MSDN on how to do that.

Open your process template that you want to use the new custom activity and Right-click on the Toolbox and browse to the created library as the following image.
Add custom activity for The Visual Studio Toolbox

Drag and drop your new custom activity, declare a new variable (MyValue) to hold the return value from the reading process as the following image.
ReadFromXML Activity

The Build summary will be as the following image.
Build Summary

The build log will be as the following image.
Build Log


Make the activity return list of string

We will need to define OutArgument as List<string> and assign that in the execute method
OutArgument as list of string

Declare a variable (MyValue) but this time the type is List<string> too
Drag and drop For each Activity of string and print each item in the list as the followingReadFromXML Activity for list of string


The Build summary will be as the following image.
Build Summary for list of string

Versioning Assembly during TFS Build 2013

My fellows MVPs Colin Dembovsky and Ricci Gian Maria had great posts on doing Assembly Versioning, it doesn’t cover my case but they helped me very well. Thanks guys :-)

First, It’s better to understanding the Assembly version.

Assembly versions consist of four different parts ({Major Version}.{Minor Version}.{Build Number}.{Revision Source Control Revision})


Major: The main version of the product. For example the Major of all the VisualStudio 2012 assemblies are 11 and VisualStudio 2013 are 12.

Minor: Small changes that doesn’t required changing in Application interfaces, so it will not break other application it depends on. This number will be reset to zero when the Major number changes.

Build: Using this number you can find the build on the build server.

Revision: This is the number from source control for that build number.

See the following image:
VS Version

We can see in the previous image that the Version is different from the File Version? so why this happen?

To answer this question we need to know that you don’t have to do that, but as the Version is the version that .NET uses when linking assemblies, so you might want to keep the Version without the build number and the revision as you may want to change something, it might be only changing in the build parameters and you don’t want to rebuild all dependent assemblies.

Using one AssemblyInfo.cs for all projects within the same solution

We might want to use one file to maintain the Version and the File version for all projects as the following:

  • Create AssemblyInfo.cs as a solution file, it will include AssemblyVersion and AssemblyFileVersion attributes
  • Add an exiting item for all your projects as a linked item to point to that file
  • Remove the AssemblyVersion and AssemblyFileVersion attributes from all the project AssemblyInfo.cs files.

Add exiting item as link


Versioning Assembly during TFS Build

The idea hear is to change the number in the AssemblyInfo.cs during the build and before the compiling happen.

In my case I use a PowerShell script and I customize my process as the following:


[string]$searchFilter = "AssemblyInfo*.*",



$extractedBuildNum = $buildNumIncludeBuildDefination.substring($buildNumIncludeBuildDefination.LastIndexOf(".")+1 ,(($buildNumIncludeBuildDefination.length)- ($buildNumIncludeBuildDefination.LastIndexOf("."))-1))
$chageset = $chagesetWithC.substring($chagesetWithC.LastIndexOf("C")+1 ,(($chagesetWithC.length)- ($chagesetWithC.LastIndexOf("C"))-1))

$assemblyVersion = $assemblyVersion.Replace("B", $extractedBuildNum).Replace("R", $chageset)
$fileAssemblyVersion = $fileAssemblyVersion.Replace("B", $extractedBuildNum).Replace("R", $chageset)

gci -Path $pathToSearch -Filter $searchFilter -Recurse | %{
Write-Host " -> Changing $($_.FullName)"

# remove the read-only bit on the file
sp $_.FullName IsReadOnly $false

# run the regex replace
(gc $_.FullName) | % { $_ -replace 'AssemblyVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)', "AssemblyVersion(""$assemblyVersion"")" }| sc $_.FullName
(gc $_.FullName) | % { $_ -replace 'AssemblyFileVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)', "AssemblyFileVersion(""$fileAssemblyVersion"")" }| sc $_.FullName
Write-Host "Done!"
Write-Host $assemblyVersion
Write-Host $fileAssemblyVersion
Write-Host $extractedBuildNum

catch {
Write-Host $_
exit 1

I opened the process template and within “Try Compile and Test” I added If sequence activity 
In Try and Compile I add if squence

The main activity inside the “If” activity will be InvokeProcess as the following:
VersionAssembly InvokeProcess

I sent argument to the PowerShell script as the following:
Argument for PowerShell

To set parameters in the build definition, see the following image:

Remember if you want to not change the Version number, remove B.R and Add 0.0 instead ex (

Download the Process Template

Download PowerShell Script

Creating and Deploying Web Package during TFS Build 2013

I have an old post that do the same concept with TFS 2010 but as usual there are some differences with TFS 2013:-)

How to run remote deploy with MS Deploy

I tried many ways from many blog posts, they are almost the same but none of them worked for me, so I decide to create my own solution and share that include the Build Process Template
Of course I needed to install MSDeploy (Web Deploy 3.5) on the Build machine

Customize the process template as the following:

Note: I didn’t include the error handling during the customization, you may need to do that :-)

  • Adding ConverWorkspaceItem and If activities, we could add ConverWorkspaceItem part of the If sequence, this even could be better, you can do that too :-)
    ConvertWorkspaceItem and Create packge with Deploy
  • The ConverWorkspaceItem will transform the web application selected in the build definition to a local path
  • In the If activity the main 2 activities are, Create Package (MSBuild activity) and Deploy Package (InvokeProcess activity)
    Create and Deploy package workflow
  • The Create Package activity will be as the following:
    • Configuration —> the configuration that entered in the build definition
    • CommandLineArgument —->  /t:build;publish
    • Project —-> the project that transformed from ConverWorkspaceItem activity

Create Package - MSBuild

  • The Deploy Web Package (InvokeProcess) activity will be as the following image:
    Deploy Web Package InvokeProcess
  • The created package on the working directory on the build agent will be as the following:
    Web Package
  • The Deployment section on the build definition will be as the following:
  • How to test the create deployment file on the build agent
    Run file.Deploy.cmd
  • How to publish without a package using a publish profile
    Run MSBuild with publish profile
  • How to add a parameters value inside the parameter file.xml that created with the package
    Create Web package and add one paramter in the file

Download the process Template


Debugging TFS Job Agent Extension

Creating TFS Job Agent was not difficult at all but debugging it was a pain in the nick! :-)

here I explain how to find what the error and how to fix that

Extension not found for TFSJobAgent (ExtensionNotFound)

So first how to know if my job agent succeeded or failed and if it’s failed, why this happen?

How to see this

Open the following link:


Click on the job history, if the job failed you will see it here and you can click on the small arrow to see History or DefinitionTFS Job Definition and History

TFS Job History Details

TFS Job Definition Details

In case there is nothing in the history you should see your job on the Job Motoring page as the following:
TFS Job Monitoring

Remember you will need to restart the TFS Job Agent every time you deploy a new version of the dll so the service can load the assembly and this the reason for the fail first time.
Restart TFS Job Agent


TFS2012: New tools for TFS Administrators

 Identity Synchronization in Team Foundation Server 2010

Deploying SSDT During Local and Server Build

Updated on 26/1/2015
4 years ago, I wrote a post about how to deploy VS DB (Visual Studio Database Project) to your local SQL Server during your local build.

As you may already know that a new version of SSDT (SQL Server Data Tool) has been released with VS 2012 to replace the normal VS DB project that was existing with VS 2010 and of course the deployment changed.

For more information and understadning about SSDT, see this post:
What’s New in TFS 2012?- SSDT (SQL Server Data Tool)

Now we have a feature called publish profile which you can put all your setting in that file and use it afterwards to deploy the DB.

This post has 2 section:

  • Deploy and publish SSDT to local SQL Server during local build
  • Deploy and publish SSDT to a shared SQL Server during TFS Build

Deploy and publish SSDT to local SQL Server during local build

If  you need to work with SSDT for SQL Server 2014, then you will need to install the last SSDT, it’s not included in VS update 3, download SSDT
SSDT for SQL Server 2014

1.Using SqlPublishTask of MSBuild
I edit the SSDT project file as the following:
local publish SSDT

<Target Name="DeployDB" AfterTargets="build" Condition="'$(Configuration)' == 'Local'">
<Message Importance="high" Text="************** Star Deploying DB **************" />
<Message Importance="high" Text="Deploying Project: $(MSBuildProjectDirectory)\$(MSBuildProjectName).sqlproj" />
<Message Importance="high" Text="Deployment Profile: $(MSBuildProjectDirectory)\PublishProfiles\$(MSBuildProjectName).local.publish.xml" />
<MSBuild Projects="$(MSBuildProjectDirectory)\$(MSBuildProjectName).sqlproj" Properties="SqlPublishProfilePath=$(MSBuildProjectDirectory)\PublishProfiles\$(MSBuildProjectName).local.publish.xml" Targets="sqlPublish" />

I used some of MSBuild Reserved and Well-Known Properties like $(MSBuildProjectName) and $(MSBuildProjectDirectory), for complete list, click on this link


2.Using MS Build Command line with SqlPublishTask

MSBuild SqlPublishTask  command line

msbuild /t:build;publish "C:\TFS Source\Model\Calculator\Calculator.DB\Calculator.DB.sqlproj" /p:SqlPublishProfilePath="C:\TFS Source\Model\Calculator\Calculator.DB\PublishProfiles\Calculator.DB.local.publish.xml" 

"$(MSBuildProgramFiles32)\MSBuild\12.0\Bin\msbuild" /t:build;publish "C:\TFS Source\Model\Calculator\Calculator.DB\Calculator.DB.sqlproj" /p:SqlPublishProfilePath="C:\TFS Source\Model\Calculator\Calculator.DB\PublishProfiles\Calculator.DB.local.publish.xml"
  • If we run the MS Build from withing the project path we can use relative paths instead of absolute paths
  • To use MSBuild without path, we need to open Visual Studio command line otherwise we may having this error “exited with code 9009” which means it couldn’t find the MSBuild.exe”, so I will need to use the full path and this is always the case when working with pre and post build events


3.Using SqlPackage.exe

SqlPackage.exe is a command line utility that automate some of the DB development tasks

We can call SqlPackage as a post build event for SSDT project as the following:

"$(MSBuildProgramFiles32)\Microsoft SQL Server\110\DAC\bin\sqlpackage" /a:publish /sf:"$(SolutionDir)\$(ProjectName)\$(OutputPath)\Calculator.DB.dacpac" /pr:"$(SolutionDir)\$(ProjectName)\Calculator.DB.local.publish.xml"

The .dacpac file is the output of building sqlproject, as the dll is the output of building a class library

Deploy and publish SSDT to a shared SQL Server during TFS Build

There are many ways too, the SSDT’s team blog create a great post for all ways, for more info, click on the following link:
SQL Server Database Projects and Team Foundation Build

1.Using SqlPublishTask of MSBuild
I will send some MDBuild arguments in the build definition as the following:

/t:Build;Publish /p:SqlPublishProfilePath=../Calculator.DB\PublishProfiles\Calculator.DB.local.publish.xml

But because my solution has many projects not only SSDT project, which means I build the solution file not the SSDT project file only, this means, the build argument will be sent to each project file in the solution and this gives error with one of the Win Form project as the following:

MSBuild error MSB3021: Unable to copy file C:\Program Files (x86)\MSBuild\12.0\bin\amd64\Microsoft.Common.CurrentVersion.targets (4691): Could not copy the file “exe.manifest” because it was not found.

This error will disappear if we only build SSDT, of course I can use other ways like using SqlPackage.exe with custom build but as this is the way I did on my local build, I prefered to be the same on the Build server, so I customize the build as the following

SSDT with TFSBuild

I used 2 editors:

  • Microsoft.TeamFoundation.Build.Controls.BuildProjectListEditor
  • Microsoft.TeamFoundation.Build.Controls.StringListEditor

Which makes me be able to select multiple build project and multiple publish profiles, for more info about Build Editors, see the following post:
TFS Build Editors and Build Process Metadata

Beginning of the update

To customize the process I added 2 arguments and I added them to the meatadata to categorize them under SSDT section in the Build definition

SSDT Section

I used MSBuild activity to run MSBuild for the SSDT projects that selected by the build definition
Run MSBuild for SSDT

You can download the process template by click on the following link:
TFS Process Template

Migrating Team Foundation Server 2013 Databases and all Databases in SharePoint 2013 to a New Server

This post could be used for many scenarios as the following,

Scenario 1:
Migrate Team Foundation Server’s SQL Server to another machine, Migrating Team Foundation Server Databases, moving TFS configuration Database to another SQL Server

Following  steps:
Step-1, step-2, step-4, step-5, step-6, step-7, step-8, step-9, step-11, step-13


Scenario 2:
Move all databases in SharePoint 2013, Moving SharePoint Content Databases to a New Server, Migrate SharePoint’s SQL Server to another SQL Server, Moving SharePoint to a different SQL server

Following  steps:
Step-1, step-3, step-4, step-5, step-7, step-10, step-12


Scenario 3:
Migrating Team Foundation Server Databases and all databases in SharePoint 2013 to a New Server

Following  steps:
All steps

The list of all steps:

  1. Installing MS SQL Server 2014
  2. Stop IIS and all TFS Services
  3. Stop IIS and all SharePoint Services
  4. Share a folder and turn off firewall
  5. Backup DBs and store them on the shared folder
  6. Backup SQL Server Reporting encryption key
  7. Restore DBs to the new SQL Server machine
  8. Remap Reporting DB and restore encryption key
  9. Remap and configure TFS for the new DB server
  10. Remap and configure SharePoint for the new DB server
  11. Start IIS and all TFS Services again
  12. Verify SharePoint DB migration
  13. Verify TFS DB migration
  14. Note-1 DotNet Framework cannot be installed
  15. Note-2 Fix SharePoint error cannot open DB
  16. Note-3 Fix SharePoint error cannot open sites
  17. Note-4 Repair TFS connection with SharePoint
  18. Note-5 Analysis DB backup and restore


1-Installing MS SQL Server 2014

2-Stop IIS and all TFS Services

3-Stop IIS and all SharePoint Services

4- Share a folder and turn off firewall

5-Backup DBs and store them on the shared folder

6-Backup SQL Server Reporting encryption key

7-Restore DBs to the new SQL Server machine

8-Remap Reporting DB and restore encryption key

9-Remap and configure TFS for the new DB server

10-Remap and configure SharePoint for the new DB server

11-Start IIS and all TFS Services again

12-Verify SharePoint DB migration

13-Verify TFS DB migration

14-Note-1 DotNet Framework cannot be installed

15-Note-2 Fix SharePoint error cannot open DB

16-Note-3 Fix SharePoint error cannot open sites

17-Note-4 Repair TFS connection with SharePoint

18-Note-5 Analysis DB backup and restore