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

发布于 2024-08-30 13:57:46 字数 6343 浏览 3 评论 0原文

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

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

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

我按照这篇博文了解如何让构建工作起来,我就快到了。

梳理日志文件中的失败情况,我发现以下内容:

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.

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

谁能指出我正确的方向以使其成功构建?

非常感谢, 尼克

编辑:添加 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>

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情徒 2024-09-06 13:57:46

您必须打开“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' />

这对我有用

干杯

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

幻想少年梦 2024-09-06 13:57:46

我认为您需要在 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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文