<p>I am having trouble getting Team Build to execute my MbUnit unit tests. I have tried to edit TFSBuild.proj and added the following parts:</p>

<pre><code>&lt;Project ...&gt;
  &lt;UsingTask TaskName="MbUnit.MSBuild.Tasks.MbUnit" AssemblyFile="path_to_MbUnit.MSBuild.Tasks.dll" /&gt;
  ...
  ...
  &lt;ItemGroup&gt;
    &lt;TestAssemblies Include="$(OutDir)\Project1.dll" /&gt;
    &lt;TestAssemblies Include="$(OutDir)\Project2.dll" /&gt;
  &lt;/ItemGroup&gt;
  &lt;Target Name="Tests"&gt;
    &lt;MbUnit
      Assemblies="@(TestAssemblies)"
      ReportTypes="html"
      ReportFileNameFormat="buildreport{0}{1}"
      ReportOutputDirectory="." /&gt;
  &lt;/Target&gt;
  ...
&lt;/Project&gt;
</code></pre>

<p>But I have yet to get the tests to run.</p>

The way ItemGroups in MSBuild work is that they are evaluated at the very start of the MSBuild scripts, before any targets are ran.  Therefore if the assemblies don't exist yet (which they will not because they have not been built yet) then the ItemGroups will not find any files.
The usual pattern in MSBuild to work around this is to re-call MSBuild again at this point so that when the item groups get evaluated in the inner MSBuild execution, the assemblies will exist.
For example, something like:
```
```
<PropertyGroup>
    <TestDependsOn>
      $(TestDependsOn);
      CallMbUnitTests;
    </TestDependsOn>
  </PropertyGroup>

  <Target Name="CallMbUnitTests">
    <MSBuild Projects="$(MSBuildProjectFile)"
             Properties="BuildAgentName=$(BuildAgentName);BuildAgentUri=$(BuildAgentUri);BuildDefinitionName=$(BuildDefinitionName);BuildDefinitionUri=$(BuildDefinitionUri);
                         BuildDirectory=$(BuildDirectory);BuildNumber=$(BuildNumber);CompilationStatus=$(CompilationStatus);CompilationSuccess=$(CompilationSuccess);
                         ConfigurationFolderUri=$(ConfigurationFolderUri);DropLocation=$(DropLocation);
                         FullLabelName=$(FullLabelName);LastChangedBy=$(LastChangedBy);LastChangedOn=$(LastChangedOn);LogLocation=$(LogLocation);
                         MachineName=$(MachineName);MaxProcesses=$(MaxProcesses);Port=$(Port);Quality=$(Quality);Reason=$(Reason);RequestedBy=$(RequestedBy);RequestedFor=$(RequestedFor);
                         SourceGetVersion=$(SourceGetVersion);StartTime=$(StartTime);Status=$(Status);TeamProject=$(TeamProject);TestStatus=$(TestStatus);
                         TestSuccess=$(TestSuccess);WorkspaceName=$(WorkspaceName);WorkspaceOwner=$(WorkspaceOwner);
                         SolutionRoot=$(SolutionRoot);BinariesRoot=$(BinariesRoot);TestResultsRoot=$(TestResultsRoot)"
             Targets="RunMbUnitTests"/>
  </Target>

  <ItemGroup>
    <TestAssemblies Include="$(OutDir)\Project1.dll" />
    <TestAssemblies Include="$(OutDir)\Project2.dll" />
  </ItemGroup>
  <Target Name="RunMbUnitTests">
    <MbUnit
      Assemblies="@(TestAssemblies)"
      ReportTypes="html"
      ReportFileNameFormat="buildreport{0}{1}"
      ReportOutputDirectory="." />
  </Target>
```
```
Hope that helps, good luck.
Martin.