构建失败 - 在TFS2008上的VS2010解决方案

时间:2010-04-27 09:31:08

标签: visual-studio-2010 msbuild mstest tfs2010

我已将VS2008 ASP.NET MVC解决方案迁移到VS2010 / MVC2 / .NET 4.0该解决方案在本地构建,所有单元测试都通过。

我们的TFS服务器仍然是TFS2008,我在通过CI构建时遇到了问题。

所有项目都成功构建,单元测试所有运行并通过但运行测试项目失败。

我跟着this blog post了解如何让构建工作,我几乎就在那里。

将日志文件归档为失败,我发现了以下内容:

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.

即使我在tfsbuild.proj中指定了ToolsVersion =“4.0”并且在构建服务器上更改了TfsBuildService.exe.config中的MSBuildPath,它看起来似乎正在尝试使用2008 MSTest工具。

有人能指出我正确的方向来成功建立这个吗?

非常感谢, 尼克

编辑:添加tfsbuild.proj文件

<?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>

2 个答案:

答案 0 :(得分:2)

您必须在“C:\ Program Files(x86)\ MSBuild \ Microsoft \ VisualStudio \ TeamBuild \ Microsoft.TeamFoundation.Build.targets”中打开配置文件,

删除以下2个条目:

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

<UsingTaskTaskName="TestToolsTask"...

并添加以下条目(将替换之前的条目并强制使用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' />

这对我有用

干杯

答案 1 :(得分:1)

我认为您需要在CI服务器上安装正确版本的MSTest才能实现此目的。

如果您已拥有正确版本的MSTest,请确保您的测试项目引用 Microsoft.VisualStudio.QualityTools.UnitTestFramework v10.0.0.0

确定MSTest路径,TestToolsTask任务:

  • 检查测试项目引用的程序集 Microsoft.VisualStudio.QualityTools.UnitTestFramework 的版本
  • 通过查看HKEY_LOCAL_MACHINE \ Software \ Microsoft \ VisualStudio \ $(VERSION).0中的寄存器来获取与该版本匹配的Visual Studio的InstallDir。如果密钥不存在,则将采用默认版本的路径(tfs2008为9.0)

因此,如果您的测试项目引用了版本10并且安装了Visual Studio 2010,则应自动调用MSTest。


如果您安装了TeamBuild版本3(文件 C:\ Program Files \ MSBuild \ Microsoft \ VisualStudio \ TeamBuild \ Microsoft.TeamFoundation.Build.targets 具有属性 TeamBuildVersion 设置为3)您可以将任务 TestToolsTask 的MSBuild属性 TestToolsTaskToolPath 覆盖到新版本的MSTest。

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

您还需要检查 tfsbuild.proj 中的属性 ProjectFileVersion 是否大于2。

<ProjectExtensions>
  ...
  <ProjectFileVersion>3</ProjectFileVersion>
  ...
</ProjectExtensions>