1
votes

I am trying to create a custom MSBuild task that will run my nUnit tests either locally or during a TFS2010 build. The script works great locally but I can't seem to find the test dlls on the TFS build server. I'm using a task in the MSBuild.ExtensionPack to run the unit tests (again this works fine locally).

The Assemblies list is always empty. TargetDir shows the path is "C:\Builds\2\Product1\ci.product1.acme.com\Binaries\" which looks right to me. I also tried to kick off my target after the CoreCompile target instead within the AfterBuild target with no change.

I've probably made some stupid mistake but I'm in kill me mode at this point. Please help.

  <PropertyGroup>
    <RunTFSBuild>false</RunTFSBuild>
    <SolutionDirectory>$(MSBuildProjectDirectory)\..</SolutionDirectory>
    <ExtensionTasksPath>$(SolutionDirectory)\_shared\MSBuild\</ExtensionTasksPath>
    <TPath>$(ExtensionTasksPath)MSBuild.ExtensionPack.tasks</TPath>
    <NUnitOutputFile>$(SolutionDirectory)\nUnitResults.xml</NUnitOutputFile>
    <NUnitOutputFileAsMsTest>$(SolutionDirectory)\nUnitResultsAsMsTestResults.xml</NUnitOutputFileAsMsTest>
    <ToolPath>$(SolutionDirectory)\_shared\MSBuild\nUnit_2.5.7</ToolPath>
  </PropertyGroup>
  <Import Project="$(TPath)" />

  <Target Name="AfterBuild">     
    <CallTarget Condition="$(RunTFSBuild)!='true'" Targets="NUnitTestRunner" />
    <CallTarget Condition="$(RunTFSBuild)=='true'" Targets="NUnitTestRunner;TFSNUnitTestRunner" />
  </Target>
  <Target Name="NUnitTestRunner">
    <ItemGroup >
      <Assemblies Include="$(SolutionDirectory)\**\bin\$(Configuration)\*.nUnit.Tests.dll" />
    </ItemGroup>
    <ItemGroup Condition="$(RunTFSBuild)=='true'">
      <Assemblies Include="$(TargetDir)\**\*.nUnit.Tests.dll" />
    </ItemGroup>

    <Message Text="SolutionDirectory=$(SolutionDirectory)" />
    <Message Text="ExtensionTasksPath=$(ExtensionTasksPath)" />
    <Message Text="TargetDir=$(TargetDir)" />
    <Message Text="TPath=$(TPath)" />
    <Message Text="NUnitOutputFile=$(NUnitOutputFile)" />
    <Message Text="Running nUnit tests from: $(Assemblies)" />
1

1 Answers

1
votes

1) Try to change property RunTFSBuild

<RunTFSBuild Condition="'$(RunTFSBuild)'==''">false</RunTFSBuild>

2) Replace sections (it may be just cleaning of project, but it may be very important due to some limitations of CallTarget):

<Target Name="AfterBuild" DependsOnTargets="NUnitTestRunner;TFSNUnitTestRunner" />     
<Target Name="TFSNUnitTestRunner" 
        Condition="$(RunTFSBuild)=='true'">
    <!-- TFSNUnitTestRunner Body -->
</Target>

3) If 1) and 2) willn't be helpful try to set verbose of the build to diagnostic (msbuld key /v:diag). Find all calls of TFSNUnitTestRunner in the log and you will see what is actually happened on TFS.

EDIT: *Assemblies* is declared as ItemGroup. Use @(Assemblies) to access items:

<Message Text="Running nUnit tests from: @(Assemblies)" />

Property $(Assemblies) will always be empty in your case.