Archive for the ‘team foundation’ Category

Data Driven Unit Tests fail during TFS 2008 Build…

Wednesday, June 11th, 2008

but not when executed in Visual Studio 2008.

Error Message:
The unit test adapter failed to connect to the data source or to read the data. For more information on troubleshooting this error, see "Troubleshooting Data-Driven Unit Tests" ( in the MSDN Library.
Error details: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

Solution: Don't specify the connection string and the table in the constructor of the DataSource attribute, but follow this (use the configuration section).

Make sure you specify Version 9.0.0 and not 8.0.0 like in the sample!

Delete of Team Foundation Server Builds

Tuesday, September 11th, 2007

environment Team Foundation Server 2005

problem Delete all builds except the most 10 recent

solution Using powershell


powershell.exe c:\DirWherePs1FileIs\CleanupNightlyBuildDontCallMe.ps1



$tfbuild="C:\\Program Files\\Microsoft Visual Studio 8\\Common7\\IDE\\TFSBuild.exe"

# sort by time
$dirs=(ls "c:\\DropLocation\\BuildLabel_*" | sort -property LastWriteTime -desc)

# delete all except the newest 10 ([math]::max)
# -f op
$dirs | select -last ([math]::Max($dirs.length-10,0)) `
| %{ .$tfbuild delete http://tfsserver:8080 TuT ('"{0}"' -f $_.Name) /noprompt }

Team Foundation Server Directory Download

Friday, May 25th, 2007

environment Team Foundation Server

problem Download a directory from TFS with a specified label without creating a workspace and minimal install dependencies

solution Source or Binary

The binary has same library dependencies and I'm not sure if I'm allowed to redistribute those .dlls:


x64 Support

  1. Make sure you have added the TeamFoundation .dlls from C:\\Program Files\\... and NOT from the GAC (details)
  2. Build with "CPU Any" and copy .dlls to target machine
  3. Build with "x86" and copy executable to target machine

Automatic AssemblyInfo generation during Team Build

Wednesday, May 16th, 2007

environment Team Foundation Server, msbuild, each projects is located below the solution file

problem Provide team build number and flavor (debug, release) for compiled assemblies from multiple projects in a solution

solution Edit your .csproj files (make sure you do a "Checkout for edit") and add

  <Import Project="..\\AssemblyInfo.proj" />

The AssemblyInfo.proj should be placed next to the .sln file:

<Project xmlns="">
  <Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
  <Target Name="BeforeBuild">
    <Attrib Files="Properties\AssemblyInfo.cs" Normal="true"/>

    <!-- Build := Days since StartDate; Revision := 65534 / (24*60*60) * seconds since midnight :) -->
    <Version BuildType="Automatic" RevisionType="Automatic" StartDate="2007/01/01" Major="1" Minor="0">
      <Output TaskParameter="Major" PropertyName="Major" />
      <Output TaskParameter="Minor" PropertyName="Minor" />
      <Output TaskParameter="Build" PropertyName="Build" />
      <Output TaskParameter="Revision" PropertyName="Revision" />

    <AssemblyInfo CodeLanguage="CS"
        AssemblyCompany="Company Name"
        AssemblyProduct="$(AssemblyName) $(Configuration) $(BuildNumber)"
        AssemblyCopyright="Copyright Company Name 2007"
      	AssemblyFileVersion="$(Major).$(Minor).$(Build).$(Revision)" />

    <Attrib Files="Properties\AssemblyInfo.cs" ReadOnly="true"/>

You need to install msbuildtasks on your local machine AND the build server. Apart from the Team Build revision, you'll get another auto-generated assembly revision.

debugging Unload, Reload the project after every change to AssemblyInfo.proj

links MSBuild infos

Database setup before UnitTests for each configuration with Team Foundation/MSBuild

Friday, April 20th, 2007

environment .Net Project, Team Foundation Server, MSBuild

problem Nightly Build containing multiple configurations (e.g. debug, release,...) and the requirement to install a database before the testcases are executed. It is not enough to install the database once for all configurations.

Initial we overwrote the BeforeTest target, but this is getting called only once for all configurations.


Edit TFSBuild.proj

<!-- copied from C:\\Program Files\\MSBuild\\Microsoft\\VisualStudio\\v8.0\\TeamBuild\\Microsoft.TeamFoundation.Build.targets -->
<Target Name="CoreTest"
        DependsOnTargets="$(CoreTestDependsOn)" >

        Condition="!Exists('$(TestResultsRoot)')" />

        Properties="BuildNumber=$(BuildNumber);Platform=%(ConfigurationToBuild.PlatformToBuild);Flavor=%(ConfigurationToBuild.FlavorToBuild);IsDesktopBuild=$(IsDesktopBuild)" />

<Target Name="RunTestWithConfigurationWithDB" >
  <!-- Make sure the Database is freshly setup for each FlavorToBuild -->

  <!-- Database Setup -->
  <Message Text="Creating fresh database. Flavor: $(Flavor) Platform: $(Platform) IsDesktopBuild: $(IsDesktopBuild)"/>

  <Exec Command="db.init.cmd" Timeout="1200000" WorkingDirectory="somedir)"/>

        Properties="BuildNumber=$(BuildNumber);Platform=$(Platform);Flavor=$(Flavor);IsDesktopBuild=$(IsDesktopBuild)" />

references Search for 'How To: Batch Tasks with Item Metadata' in MSDN. This gave me a good idea when targets are called multiple times and when not.