【问题标题】:VS Test failing in Pipelines with missing 'Microsoft.NET.Test.Sdk'VS 测试在管道中失败,缺少“Microsoft.NET.Test.Sdk”
【发布时间】:2018-11-14 16:24:50
【问题描述】:

由于我的构建管道中的 Visual Studio 测试 步骤失败,我的构建失败。

我有一个简单的 .NET Core v2.1 类库和关联的 MS 测试库。我的管道中有两个步骤:

  1. .NET Core 构建步骤,以及
  2. Visual Studio 测试步骤

两个项目都以netcoreapp2.1 框架为目标,.csproj 文件见下文。

我已尝试启用和禁用 代码覆盖率 选项,但这没有任何区别。

提前致谢,

凯恩


.csproj 文件

主要项目

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <AssemblyName>Trustmarque.Core.ExtensionMethods</AssemblyName>
    <RootNamespace>Trustmarque.Core.ExtensionMethods</RootNamespace>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <Description>Generalised class extension methods build on the .NET Core.</Description>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
  </ItemGroup>

</Project>

测试项目

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>

    <IsPackable>false</IsPackable>

    <AssemblyName>Trustmarque.Core.ExtensionMethods.Tests</AssemblyName>

    <RootNamespace>Trustmarque.Core.ExtensionMethods.Tests</RootNamespace>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
    <PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
    <PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\ExtensionMethods\ExtensionMethods.csproj" />
  </ItemGroup>

</Project>

YAML

queue: name: Hosted VS2017 demands: vstest steps: - task: DotNetCoreCLI@2 displayName: '.NET Core Build' - task: VSTest@2 displayName: 'VS Unit Test' inputs: testFiltercriteria: /diag codeCoverageEnabled: true otherConsoleOptions: '/framework:".NETCoreApp,Version=2.1"'

测试输出日志

2018-11-14T09:33:56.0414482Z ##[section]Starting: VS Unit Test 2018-11-14T09:33:56.0420823Z ============================================================================== 2018-11-14T09:33:56.0420887Z Task : Visual Studio Test 2018-11-14T09:33:56.0420941Z Description : Run unit and functional tests (Selenium, Appium, Coded UI test, etc.) using the Visual Studio Test (VsTest) runner. Test frameworks that have a Visual Studio test adapter such as MsTest, xUnit, NUnit, Chutzpah (for JavaScript tests using QUnit, Mocha and Jasmine), etc. can be run. Tests can be distributed on multiple agents using this task (version 2). 2018-11-14T09:33:56.0420983Z Version : 2.142.12 2018-11-14T09:33:56.0421033Z Author : Microsoft Corporation 2018-11-14T09:33:56.0421089Z Help : [More information](https://go.microsoft.com/fwlink/?LinkId=835764) 2018-11-14T09:33:56.0421126Z ============================================================================== 2018-11-14T09:33:56.9036862Z SystemVssConnection exists true 2018-11-14T09:33:57.0359241Z SystemVssConnection exists true 2018-11-14T09:33:57.1181619Z Running tests using vstest.console.exe runner. 2018-11-14T09:33:57.1181728Z ====================================================== 2018-11-14T09:33:57.1182048Z Test selector : Test assemblies 2018-11-14T09:33:57.1182141Z Test filter criteria : null 2018-11-14T09:33:57.1182212Z Search folder : D:\a\1\s 2018-11-14T09:33:57.1182743Z VisualStudio version selected for test execution : latest 2018-11-14T09:33:57.8312901Z Run in parallel : false 2018-11-14T09:33:57.8314015Z Run in isolation : false 2018-11-14T09:33:57.8315114Z Path to custom adapters : null 2018-11-14T09:33:57.8319882Z Other console options : /framework:".NETCoreApp,Version=2.1" 2018-11-14T09:33:57.8320427Z Code coverage enabled : true 2018-11-14T09:33:57.8320689Z Diagnostics enabled : false 2018-11-14T09:33:57.8322155Z SystemVssConnection exists true 2018-11-14T09:33:57.8348561Z Run the tests locally using vstest.console.exe 2018-11-14T09:33:57.8348848Z ======================================================== 2018-11-14T09:33:57.8349439Z Test selector : Test assemblies 2018-11-14T09:33:57.8352816Z Test assemblies : **\*test*.dll,!**\*TestAdapter.dll,!**\obj\** 2018-11-14T09:33:57.8353669Z Test filter criteria : null 2018-11-14T09:33:57.8360790Z Search folder : D:\a\1\s 2018-11-14T09:33:57.8361971Z Run settings file : D:\a\1\s 2018-11-14T09:33:57.8369736Z Run in parallel : false 2018-11-14T09:33:57.8370326Z Run in isolation : false 2018-11-14T09:33:57.8392182Z Path to custom adapters : null 2018-11-14T09:33:57.8393171Z Other console options : /framework:".NETCoreApp,Version=2.1" 2018-11-14T09:33:57.8395168Z Code coverage enabled : true 2018-11-14T09:33:57.8396140Z Diagnostics enabled : false 2018-11-14T09:33:57.8398717Z Rerun failed tests: false 2018-11-14T09:33:57.8401805Z VisualStudio version selected for test execution : latest 2018-11-14T09:33:58.9933609Z ======================================================== 2018-11-14T09:33:58.9973631Z ====================================================== 2018-11-14T09:33:59.0613609Z [command]"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" @D:\a\_temp\69e3bc61-e7f0-11e8-8572-4338aa006dd6.txt 2018-11-14T09:34:06.3128046Z Microsoft (R) Test Execution Command Line Tool Version 15.8.0 2018-11-14T09:34:06.3130539Z Copyright (c) Microsoft Corporation. All rights reserved. 2018-11-14T09:34:06.3131113Z 2018-11-14T09:34:06.6145727Z vstest.console.exe 2018-11-14T09:34:06.6146432Z "D:\a\1\s\ExtensionMethods.Tests\bin\Debug\netcoreapp2.1\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.dll" 2018-11-14T09:34:06.6147591Z "D:\a\1\s\ExtensionMethods.Tests\bin\Debug\netcoreapp2.1\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll" 2018-11-14T09:34:06.6147793Z "D:\a\1\s\ExtensionMethods.Tests\bin\Debug\netcoreapp2.1\Trustmarque.Core.ExtensionMethods.Tests.dll" 2018-11-14T09:34:06.6149501Z /EnableCodeCoverage 2018-11-14T09:34:06.6149657Z /logger:"trx" 2018-11-14T09:34:06.6149783Z /TestAdapterPath:"D:\a\1\s" 2018-11-14T09:34:06.6149907Z /framework:".NETCoreApp,Version=2.1" 2018-11-14T09:34:12.8077290Z Starting test execution, please wait... 2018-11-14T09:34:14.8437128Z Test run will use DLL(s) built for framework .NETCoreApp,Version=v2.1 and platform X86. Following DLL(s) do not match framework/platform settings. 2018-11-14T09:34:14.8437793Z Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.dll is built for Framework 4.5 and Platform AnyCPU. 2018-11-14T09:34:14.8438215Z Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll is built for Framework 1.5 and Platform AnyCPU. 2018-11-14T09:34:14.8438617Z Go to http://go.microsoft.com/fwlink/?LinkID=236877&clcid=0x409 for more details on managing these settings. 2018-11-14T09:34:14.8438786Z 2018-11-14T09:34:23.5616980Z M i c r o s o f t ( R ) C o v e r a g e C o l l e c t i o n T o o l V e r s i o n 1 5 . 0 . 3 0 3 1 9 . 0 2018-11-14T09:34:23.5617265Z 2018-11-14T09:34:23.5617351Z 2018-11-14T09:34:23.5617457Z C o p y r i g h t ( c ) M i c r o s o f t C o r p o r a t i o n . A l l r i g h t s r e s e r v e d . 2018-11-14T09:34:23.5617498Z 2018-11-14T09:34:23.5617554Z 2018-11-14T09:34:23.5617591Z 2018-11-14T09:34:23.5617627Z 2018-11-14T09:34:24.4903850Z 2.8847 2018-11-14T09:34:25.4504736Z System.IO.FileNotFoundException: Unable to find tests for D:\a\1\s\ExtensionMethods.Tests\bin\Debug\netcoreapp2.1\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.dll. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk" and framework version settings are appropriate. Rerun with /diag option to diagnose further. 2018-11-14T09:34:25.4504927Z at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.GetTestHostProcessStartInfo(IEnumerable`1 sources, IDictionary`2 environmentVariables, TestRunnerConnectionInfo connectionInfo) 2018-11-14T09:34:25.4505025Z at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable`1 sources) 2018-11-14T09:34:25.4505077Z at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyExecutionManager.StartTestRun(TestRunCriteria testRunCriteria, ITestRunEventsHandler eventHandler) 2018-11-14T09:34:25.6678123Z M i c r o s o f t ( R ) C o v e r a g e C o l l e c t i o n T o o l V e r s i o n 1 5 . 0 . 3 0 3 1 9 . 0 2018-11-14T09:34:25.6678286Z 2018-11-14T09:34:25.6678334Z 2018-11-14T09:34:25.6678492Z C o p y r i g h t ( c ) M i c r o s o f t C o r p o r a t i o n . A l l r i g h t s r e s e r v e d . 2018-11-14T09:34:25.6678566Z 2018-11-14T09:34:25.6678623Z 2018-11-14T09:34:25.6678664Z 2018-11-14T09:34:25.6678700Z 2018-11-14T09:34:26.8351769Z M i c r o s o f t ( R ) C o v e r a g e C o l l e c t i o n T o o l V e r s i o n 1 5 . 0 . 3 0 3 1 9 . 0 2018-11-14T09:34:26.8351940Z 2018-11-14T09:34:26.8352006Z 2018-11-14T09:34:26.8352092Z C o p y r i g h t ( c ) M i c r o s o f t C o r p o r a t i o n . A l l r i g h t s r e s e r v e d . 2018-11-14T09:34:26.8352125Z 2018-11-14T09:34:26.8352155Z 2018-11-14T09:34:26.8352199Z 2018-11-14T09:34:26.8352227Z 2018-11-14T09:34:26.8788931Z 2.3838 2018-11-14T09:34:26.8898822Z System.IO.FileNotFoundException: Unable to find tests for D:\a\1\s\ExtensionMethods.Tests\bin\Debug\netcoreapp2.1\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk" and framework version settings are appropriate. Rerun with /diag option to diagnose further. 2018-11-14T09:34:26.8899122Z at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.GetTestHostProcessStartInfo(IEnumerable`1 sources, IDictionary`2 environmentVariables, TestRunnerConnectionInfo connectionInfo) 2018-11-14T09:34:26.8899942Z at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable`1 sources) 2018-11-14T09:34:26.8900007Z at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyExecutionManager.StartTestRun(TestRunCriteria testRunCriteria, ITestRunEventsHandler eventHandler) 2018-11-14T09:34:26.9247283Z M i c r o s o f t ( R ) C o v e r a g e C o l l e c t i o n T o o l V e r s i o n 1 5 . 0 . 3 0 3 1 9 . 0 2018-11-14T09:34:26.9247370Z 2018-11-14T09:34:26.9247428Z 2018-11-14T09:34:26.9247520Z C o p y r i g h t ( c ) M i c r o s o f t C o r p o r a t i o n . A l l r i g h t s r e s e r v e d . 2018-11-14T09:34:26.9247570Z 2018-11-14T09:34:26.9247619Z 2018-11-14T09:34:26.9247650Z 2018-11-14T09:34:26.9247681Z 2018-11-14T09:34:27.4568128Z M i c r o s o f t ( R ) C o v e r a g e C o l l e c t i o n T o o l V e r s i o n 1 5 . 0 . 3 0 3 1 9 . 0 2018-11-14T09:34:27.4568259Z 2018-11-14T09:34:27.4568335Z 2018-11-14T09:34:27.4568442Z C o p y r i g h t ( c ) M i c r o s o f t C o r p o r a t i o n . A l l r i g h t s r e s e r v e d . 2018-11-14T09:34:27.4568504Z 2018-11-14T09:34:27.4568543Z 2018-11-14T09:34:27.4568580Z 2018-11-14T09:34:27.4568631Z 2018-11-14T09:34:27.5016363Z 3.0114 2018-11-14T09:34:33.4517174Z M i c r o s o f t ( R ) C o v e r a g e C o l l e c t i o n T o o l V e r s i o n 1 5 . 0 . 3 0 3 1 9 . 0 2018-11-14T09:34:33.4517363Z 2018-11-14T09:34:33.4517409Z 2018-11-14T09:34:33.4517517Z C o p y r i g h t ( c ) M i c r o s o f t C o r p o r a t i o n . A l l r i g h t s r e s e r v e d . 2018-11-14T09:34:33.4517603Z 2018-11-14T09:34:33.4517641Z 2018-11-14T09:34:33.4517678Z 2018-11-14T09:34:33.4517715Z 2018-11-14T09:34:33.7048135Z Passed Timestamp_DateTime_CurrentDateTime_FormatAndValuesMatch 2018-11-14T09:34:33.7048569Z Passed ToJson_Object_ReturnsStringRepresentation 2018-11-14T09:34:33.7048660Z Passed ToJsonString_Object_ReturnsStringRepresentationIncludingObjectType 2018-11-14T09:34:33.7049036Z Passed IsNullOrEmpty_String_EmptyAndNullValues 2018-11-14T09:34:33.7049135Z Passed IsNullOrEmpty_String_NonEmptyOrNullValues 2018-11-14T09:34:33.7049190Z Passed Parse_String_ValidTypeParses_CorrectTypes 2018-11-14T09:34:33.7049257Z Passed Parse_String_ValidTypeParses_DefaultTypes 2018-11-14T09:34:33.7049297Z Passed FromJson_String_ValidObjects 2018-11-14T09:34:33.7049338Z Passed FromJson_String_InvalidObjects 2018-11-14T09:34:33.7049402Z Passed IsValidEmailAddress_String_ValidEmailAddresses_ReturnTrue 2018-11-14T09:34:33.7049465Z Passed IsValidEmailAddress_String_InvalidEmailAddresses_ReturnFalse 2018-11-14T09:34:35.8172642Z Results File: D:\a\1\s\TestResults\VssAdministrator_factoryvm-az552_2018-11-14_09_34_33.trx 2018-11-14T09:34:35.8203749Z 2018-11-14T09:34:35.8210373Z Attachments: 2018-11-14T09:34:35.8210758Z D:\a\1\s\TestResults\6c92c0b5-2e35-48af-867a-2a4575306a68\VssAdministrator_factoryvm-az552 2018-11-14 09_34_22.coverage 2018-11-14T09:34:35.8211079Z 2018-11-14T09:34:35.8211397Z Total tests: Unknown. Passed: 11. Failed: 0. Skipped: 0. 2018-11-14T09:34:35.8211670Z Test Run Aborted. 2018-11-14T09:34:35.8211939Z Test execution time: 10.7395 Seconds 2018-11-14T09:34:36.0240507Z ##[warning]Vstest failed with error. Check logs for failures. There might be failed tests. 2018-11-14T09:34:36.0769776Z ##[error]Error: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe failed with return code: 1 2018-11-14T09:34:36.3170630Z ##[error]VsTest task failed. 2018-11-14T09:34:36.3566464Z ##[section]Async Command Start: Publish test results 2018-11-14T09:34:36.4181634Z Publishing test results to test run '6' 2018-11-14T09:34:36.4181725Z Test results remaining: 11. Test run id: 6 2018-11-14T09:34:36.9962474Z Published Test Run : https://dev.azure.com/TrustmarqueIT/Test_2018-10-30/_TestManagement/Runs#runId=6&_a=runCharts 2018-11-14T09:34:36.9971952Z ##[section]Async Command End: Publish test results 2018-11-14T09:34:36.9972803Z ##[section]Finishing: VS Unit Test

【问题讨论】:

  • 您是否尝试在您的dotnet build 之前添加dotnet restore 任务以确保正确安装了依赖项?
  • 嗨@Jayendran,感谢您的建议。我没有dotnet restore 步骤,添加了它,但它仍然失败。这是 YAML:resources: - repo: self queue: name: Hosted VS2017 demands: vstest steps: - task: DotNetCoreCLI@2 displayName: '.NET Core Restore' inputs: command: restore - task: DotNetCoreCLI@2 displayName: '.NET Core Build' - task: VSTest@2 displayName: 'VS Unit Test' inputs: testFiltercriteria: /diag codeCoverageEnabled: true otherConsoleOptions: '/framework:".NETCoreApp,Version=2.1"'
  • 您是否尝试过默认的 .NET Core 构建管道模板?这在不改变任何东西的情况下有效吗?
  • 嗨@JonathanTwite,我认为您在谈论原始YAML 中的DotNetCoreCLI@2 步骤。据我所知,这是标准的 .NET Core 构建管道模板。这本身就没有问题。当我添加测试步骤时,问题就来了。此外,使用标准 Azure Repos 构建模板可以完美运行,但不会运行测试步骤,因为它是在 Ubuntu 上构建的,添加测试步骤或更改 vmImage 的唯一方法是编辑 YAML ,我严重缺乏的专业领域...... ;-)
  • 我建议您尝试 DevOps 前端提供的构建模板(完整构建,而不是单个任务),而不是自己编写 YAML - 如果可行,您可以进行比较。跨度>

标签: azure-devops azure-pipelines azure-pipelines-build-task


【解决方案1】:

我通过修改过滤器来查找测试程序集解决了我的问题。当我搞乱我的测试步骤时,不小心将过滤器设置为“/**/UnitTests.dll”,我没有意识到它也匹配“obj”文件夹中的 UnitTests.dll并且该文件夹没有 .deps.json 文件。从日志中我注意到它运行了两次测试(每个匹配的 dll 一次),所以我通过恢复过滤器以排除 obj 文件夹来忽略 obj 文件夹。所以我想在这种情况下需要注意两件事,

  1. 您的测试中必须安装“Microsoft.NET.Test.Sdk” 项目和
  2. 您的过滤器不包括或排除任何不需要的 您(不想/想要)在那里的 dll

【讨论】:

  • 不错的@Gurpreet。您可以看到,在我发布的示例中,我过滤了 Path to project(s) 字段中的测试项目。不确定这对您的情况是否有帮助。
  • 对于任何想要示例过滤器的人,您可以使用**/bin/**/*.Tests.dll 之类的东西,这将确保仅执行bin 文件夹中的DLL。最后一段需要根据测试项目的命名方式进行修改。
  • 这应该被标记为正确/最佳答案。正确设置过滤器是要走的路。仔细检查管道中的输出以寻找线索。这是对我有用的过滤器:gist.github.com/ManfredLange/0275b01bdbd6df61b352fe586a4b224d
【解决方案2】:

如果有人在升级到 .Net 5.0 后得到这个,它现在会在 ref 文件夹中创建一个引用程序集,与输出程序集同名。您需要在搜索条件中忽略这一点: !**/ref/**

【讨论】:

  • 另一个选项是禁用参考程序集生成,方法是在项目文件中放置:false
  • 谢谢你救了我!
【解决方案3】:

感谢@Gurpreet 提示我记录我的解决方案。

已经有一段时间了,所以我对这些步骤的记忆有点动摇,但我相信我的错误是认为,在选择源存储库后的第一个屏幕上,我认为列出的模板是所有可用的并且 Empty jobYAML 模板相同。我错误地认为空作业意味着我必须自己编辑 YAML。

Jonathan Twite 给了我一些很好的建议,但我当时并没有完全理解他的建议。

解决方案

无论如何,解决方案是选择Empty job 或滚动到底部并选择Empty pipeline,为什么它们被不同的名称引用是一个谜。

选择空模板后,下一个屏幕将为您提供默认的代理作业。单击加号,您可以添加各种不同的任务。这是我最初的错误的一部分,我将任务与上一个屏幕上的模板混淆了。

我添加了.NET Core 任务。

我更改了Display nameCommand,并确保Version 是正确的。有趣的是,Command 有许多有趣的选项,其中三个我觉得有用的是:

  • 恢复
  • 构建
  • 测试

因此,您无需添加特定的 Test 任务,而是添加 .NET Core 任务并将其配置为进行测试。这让我有点困惑,我没有意识到 .NET Core 任务也能够进行测试。

就我而言,我也开始测试部署 NuGet 包的能力,但那完全是另一回事。

我希望这对您有所帮助,并祝大家项目顺利。

凯恩

【讨论】:

【解决方案4】:

当我尝试从 azure devops 运行我的单元测试项目时,我遇到了同样的异常: ##[错误]无法找到 C:\Users\Viktor\agent_work\2\s\Source\API\VCC_uTests\obj\Release\netcoreapp3.1\VCC_uTests.deps.json。确保测试项目具有包“Microsoft.NET.Test.Sdk”的 nuget 引用。

问题是我的 $(System.DefaultWorkingDirectory) 文件夹中有 2 个 VCC.uTests.dll,vstest 基于我的运行单元测试管道步骤启动。

我可以从步骤日志中认出它:

vstest.console.exe “C:\Users\Viktor\agent_work\2\s\Source\API\VCC.uTests\bin\Release\netcoreapp3.1\VCC_uTests.dll” "C:\Users\Viktor\agent_work\2\s\Source\API\VCC.uTests\obj\Release\netcoreapp3.1\VCC_uTests.dll"

因此,我不得不修改我的运行测试步骤搜索模式: **\bin$(BuildConfiguration)**VCC_uTests.dll

这解决了我的问题,并且该步骤在我的构建管道中成功运行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-27
    • 2015-02-04
    • 1970-01-01
    • 2011-12-29
    • 1970-01-01
    • 1970-01-01
    • 2021-07-16
    • 1970-01-01
    相关资源
    最近更新 更多