views:

1310

answers:

3

I have migrated a VS2008 ASP.NET MVC solution to VS2010/MVC2/.NET 4.0 The solution builds locally and all unit tests pass.

Our TFS server is still TFS2008 and I am having problems getting the CI build to pass.

The projects all build successfully, the unit tests all run and pass but the Running Tests item fails.

I followed this blog post on how to get the build working and I'm almost there.

Combing the log file for failures I have found the following:

Test Run Completed.
Passed  1101
------------
Total   1101   
Results file:  C:\Documents and Settings\apptemetrybuild\Local Settings\Temp\Client Portal 3\CI\TestResults\apptemetrybuild_ATT15DEV01 2010-04-27 09_09_59_Any CPU_Release.trx
Test Settings: Default Test Settings
Waiting to publish...   
Publishing results of test run apptemetrybuild@ATT15DEV01 2010-04-27 09:09:59_Any CPU_Release to http://att15tfs01:8080/...
.....Publish completed successfully.   
Command:
D:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\MSTest.exe /nologo /searchpathroot:"C:\Documents and Settings\apptemetrybuild\Local Settings\Temp\Client Portal 3\CI\Binaries\Release" /resultsfileroot:"C:\Documents and Settings\apptemetrybuild\Local Settings\Temp\Client Portal 3\CI\TestResults" /testcontainer:"C:\Documents and Settings\apptemetrybuild\Local Settings\Temp\Client Portal 3\CI\Binaries\Release\\Attenda.Stargate.Security.Tests.dll" /publish:"http://att15tfs01:8080/" /publishbuild:"vstfs:///Build/Build/149" /teamproject:"Client Portal 3" /platform:"Any CPU" /flavor:"Release"
The "TestToolsTask" task is using "MSTest.exe" from "D:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\MSTest.exe".   
Loading C:\Documents and Settings\apptemetrybuild\Local Settings\Temp\Client Portal 3\CI\Binaries\Release\\Attenda.Stargate.Security.Tests.dll... 
C:\Documents and Settings\apptemetrybuild\Local Settings\Temp\Client Portal 3\CI\Binaries\Release\\Attenda.Stargate.Security.Tests.dll 
Could not load file or assembly 'file:///C:\Documents and Settings\apptemetrybuild\Local Settings\Temp\Client Portal 3\CI\Binaries\Release\Attenda.Stargate.Security.Tests.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded. MSBUILD : warning MSB6006: "MSTest.exe" exited with code 1. [C:\Documents and Settings\apptemetrybuild\Local Settings\Temp\Client Portal 3\CI\BuildType\TFSBuild.proj]   
The previous error was converted to a warning because the task was called with ContinueOnError=true.   
Build continuing because "ContinueOnError" on the task "TestToolsTask" is set to "true". 
Done executing task "TestToolsTask" -- FAILED.

It looks like it's trying to use the 2008 MSTest tool even though I have specified ToolsVersion="4.0" in the tfsbuild.proj and changed the MSBuildPath in the TfsBuildService.exe.config on the build server.

Can anyone point me in the right direction to get this to build successfully?

Many thanks, Nick

EDIT: Adding tfsbuild.proj file

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="DesktopBuild" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
  <!-- Do not edit this -->
  <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\TeamBuild\Microsoft.TeamFoundation.Build.targets" />
  <ProjectExtensions>
    <!-- Team Foundation Build Version - DO NOT CHANGE -->
    <ProjectFileVersion>3</ProjectFileVersion>
    <Description></Description>
    <BuildMachine>ATT15DEV01</BuildMachine>
  </ProjectExtensions>

  <PropertyGroup>
    <TeamProject>Client Portal 3</TeamProject>
    <BuildDirectoryPath>C:\Documents and Settings\nfoster\Local Settings\Temp\Client Portal 3\CI</BuildDirectoryPath>
    <DropLocation>\\att15dev01\Builds\Client Portal 3</DropLocation>
    <RunTest>true</RunTest>
    <RunCodeAnalysis>Never</RunCodeAnalysis>
    <WorkItemType>Bug</WorkItemType>
    <WorkItemFieldValues>System.Description=Start the build using Team Build</WorkItemFieldValues>
    <WorkItemTitle>Build failure in build:</WorkItemTitle>
    <DescriptionText>This work item was created by Team Build on a build failure.</DescriptionText>
    <BuildlogText>The build log file is at:</BuildlogText>
    <ErrorWarningLogText>The errors/warnings log file is at:</ErrorWarningLogText>
    <UpdateAssociatedWorkItems>true</UpdateAssociatedWorkItems>
    <AdditionalVCOverrides></AdditionalVCOverrides>
    <CustomPropertiesForClean></CustomPropertiesForClean>
    <CustomPropertiesForBuild></CustomPropertiesForBuild>
  </PropertyGroup>

  <ItemGroup>
    <!--  SOLUTIONS  -->
    <SolutionToBuild Include="$(BuildProjectFolderPath)/../../Trunk/Client Portal 3 CI Build.sln">
        <Targets></Targets>
        <Properties></Properties>
    </SolutionToBuild>
  </ItemGroup>

  <ItemGroup>
    <!--  CONFIGURATIONS  -->
    <ConfigurationToBuild Include="Release|Any CPU">
        <FlavorToBuild>Release</FlavorToBuild>
        <PlatformToBuild>Any CPU</PlatformToBuild>
    </ConfigurationToBuild>
  </ItemGroup>

  <ItemGroup>
    <!--  TEST ARGUMENTS  -->
    <TestContainer Include="$(OutDir)\%2aTests.dll" />
  </ItemGroup>

  <PropertyGroup>
    <!-- TEST ARGUMENTS  -->
    <TestToolsTaskToolPath>C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe</TestToolsTaskToolPath>
  </PropertyGroup>

  <ItemGroup>
    <!--  ADDITIONAL REFERENCE PATH  -->
  </ItemGroup>

  <Target Name="AfterTest">
    <GetBuildProperties TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
                        BuildUri="$(BuildUri)"
                        Condition=" '$(IsDesktopBuild)' != 'true' ">
      <Output TaskParameter="TestSuccess" PropertyName="TestSuccess"/>
    </GetBuildProperties>
    <SetBuildProperties TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
                        BuildUri="$(BuildUri)"
                        CompilationStatus="Failed"
                        Condition=" '$(IsDesktopBuild)' != 'true' and '$(TestSuccess)' != 'true' ">
    </SetBuildProperties>
  </Target>

</Project>
A: 

I think that you need to have the right version of MSTest installed on your CI server for this to work.

If you already have the right version of MSTest make sure that your test project references Microsoft.VisualStudio.QualityTools.UnitTestFramework v10.0.0.0

To determine the MSTest path, TestToolsTask task :

  • checks the version of the assembly Microsoft.VisualStudio.QualityTools.UnitTestFramework referenced by the test project
  • Get the InstallDir of Visual Studio matching the version by looking in the register in HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\$(VERSION).0. If the key doesn't exist it will take the path for the default version (9.0 for tfs2008)

So if your test project references version 10 and if Visual Studio 2010 is installed, MSTest should be called automatically.


If you have TeamBuild version 3 installed (File C:\Program Files\MSBuild\Microsoft\VisualStudio\TeamBuild\Microsoft.TeamFoundation.Build.targets have the property TeamBuildVersion set to 3) you could override the MSBuild property TestToolsTaskToolPath of the task TestToolsTask to the new version of MSTest.

<PropertyGroup>
  <TestToolsTaskToolPath>C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe</TestToolsTaskToolPath>
</PropertyGroup>

You also need to check that the property ProjectFileVersion, in your tfsbuild.proj is greater than 2.

<ProjectExtensions>
  ...
  <ProjectFileVersion>3</ProjectFileVersion>
  ...
</ProjectExtensions>
madgnome
I have VS2008 and VS2010 installed on the build server. Where can I specify which version of MSTest to use?
Nick
Try to override the property TestToolsTaskToolPath within your tfsbuild.proj file with the path to the new version of MSTest.
madgnome
Ok, where does this get added into the proj file? Most of the Google hits for this seem to be in Chinese :( I've updated my question with my tfsbuild.proj file contents...many thanks for you help so far.
Nick
Just add the PropertyGroup as defined in my answer anywhere in your tfsbuild.proj file. (http://msdn.microsoft.com/en-us/library/aa337598%28v=VS.80%29.aspx)
madgnome
Ok, I've added the snippet above into my tfsbuild.proj file and the build is still failing with the same issue. I tried adding the <TestToolsTaskToolPath> element to the test arguments PropertyGroup that is in the proj file with no success.
Nick
Ok, this time I think I've got it. You need also to modify the ProjectFileVersion defined in tfsbuild.proj to 3.
madgnome
I've updated my question with the current state of the tfsbuild.proj file. I'm still getting 'The "TestToolsTask" task is using "MSTest.exe" from "D:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\MSTest.exe".' in the log file (and the TestToolsTask is still failing)
Nick
Forgot all I said, it works only with version 3 (2010) of teambuild. Check that your test project references the library "Microsoft.VisualStudio.QualityTools.UnitTestFramework" v10.0.0.0. If version 9.0 is referenced Mstest 9.0 will be called
madgnome
Apologies for the late reply, I was out of the office yesterday.All project references and web.config references are pointing at v10 of the unit test framework. I really don't understand enough around msbuild to work out why it's still trying to use v9 :(
Nick
Just a thought, these references should be to assemblies in the GAC? Would it make a difference that the dev box is x64 but the build server is only x86? The paths to the assembles would be different ("c:\program files (x86)\" rather than just "c:\program files")
Nick
I don't think it matters. (Send me a message on twitter (On my profile), I could try to help you more easily this way))
madgnome
A: 

You also need to check that the property ProjectFileVersion, in your tfsbuild.proj is greater than 2

May i know where can i check the project file version ?The project file version is it depend on the solution file??

I faced the problem that it build solution with tool version 2.0.But i already change tool version to 4.0 in tfsbuild.config.Anyone face this problem before??Can share ??

chs
A: 

You have to open the configuration file in "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\TeamBuild\Microsoft.TeamFoundation.Build.targets",

remove the 2 following entries:

<UsingTask TaskName="Microsoft.TeamFoundation.Build.Tasks.TestToolsTask"...

and

<UsingTaskTaskName="TestToolsTask"...

and add the following entry (which will replace the previous entries and force to use MSTest v10.0):

<UsingTaskTaskName="Microsoft.TeamFoundation.Build.Tasks.TestToolsTask"
       AssemblyFile="C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\Microsoft.TeamFoundation.Build.ProcessComponents.dll"
        Condition=" '$(ProjectFileVersion)' == '2' />

This has worked for me

Cheers

antonioh