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.
solution
Edit TFSBuild.proj
<!-- copied from C:\\Program Files\\MSBuild\\Microsoft\\VisualStudio\\v8.0\\TeamBuild\\Microsoft.TeamFoundation.Build.targets -->
<Target Name="CoreTest"
DependsOnTargets="$(CoreTestDependsOn)" >
<MakeDir
Directories="$(TestResultsRoot)"
Condition="!Exists('$(TestResultsRoot)')" />
<MSBuild
Projects="$(MSBuildProjectFile)"
Targets="RunTestWithConfigurationWithDB"
Properties="BuildNumber=$(BuildNumber);Platform=%(ConfigurationToBuild.PlatformToBuild);Flavor=%(ConfigurationToBuild.FlavorToBuild);IsDesktopBuild=$(IsDesktopBuild)" />
</Target>
<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)"/>
<MSBuild
Projects="$(MSBuildProjectFile)"
Targets="RunTestWithConfiguration"
Properties="BuildNumber=$(BuildNumber);Platform=$(Platform);Flavor=$(Flavor);IsDesktopBuild=$(IsDesktopBuild)" />
</Target>
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.