unittests 在构建服务器上失败,无法加载类型 'Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior
unittests fails on build server with Could not load type 'Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior
我有一个程序集可以在我的 PC 上正常构建和单元测试,但无法在构建 PC 上进行测试。它已经失败了大约一个月。我很可能做错了什么。这是我从构建服务器得到的响应。
16:29:38 Project "xyz.Utilities.UnitTests.csproj": VSTest
16:29:40 Test run for C:\Bin\Release\net5.0-windows\xyz.Utilities.UnitTests.dll (.NETCoreApp,Version=v5.0)
16:29:40 Microsoft (R) Test Execution Command Line Tool Version 16.11.0
16:29:40 Copyright (c) Microsoft Corporation. All rights reserved.
16:29:40
16:29:40 Starting test execution, please wait...
16:29:40 A total of 1 test files matched the specified pattern.
16:29:41 An exception occurred while invoking executor 'executor://mstestadapter/v2': Could not load type 'Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior' from assembly 'Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
16:29:41 Stack trace:
16:29:41 at Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.MSTestExecutor.RunTests(IEnumerable`1 sources, IRunContext runContext, IFrameworkHandle frameworkHandle)
16:29:41 at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.RunTestsWithSources.InvokeExecutor(LazyExtension`2 executor, Tuple`2 executorUriExtensionTuple, RunContext runContext, IFrameworkHandle frameworkHandle)
16:29:41 at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.BaseRunTests.RunTestInternalWithExecutors(IEnumerable`1 executorUriExtensionMap, Int64 totalTests)
16:29:41
16:29:41
16:29:41 Test Run Failed.
16:29:41
16:29:41 Build FAILED.
16:29:41 0 Warning(s)
16:29:41 0 Error(s)
我的项目文件很简单:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0-windows</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<OutputPath>$(SolutionDir)\Bin$(Configuration)</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<OutputPath>$(SolutionDir)\Bin$(Configuration)</OutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EasyTcp" Version="4.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" />
<PackageReference Include="coverlet.collector" Version="3.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\xyz.Utilities\xyz.Utilities.csproj" />
</ItemGroup>
</Project>
我认为这与构建服务器上的 Visual Studio 版本有关。我们是 运行 Teamcity。有人知道吗?
将您的 nuget 包升级到最新版本,它应该可以解决您的问题。我认为 MSTest.TestAdapter
和 MSTest.TestFramework
.
需要 2.2.8
我已经按照建议升级了,现在可以正常使用了。
谢谢菲尔
肯尼斯
我有一个程序集可以在我的 PC 上正常构建和单元测试,但无法在构建 PC 上进行测试。它已经失败了大约一个月。我很可能做错了什么。这是我从构建服务器得到的响应。
16:29:38 Project "xyz.Utilities.UnitTests.csproj": VSTest
16:29:40 Test run for C:\Bin\Release\net5.0-windows\xyz.Utilities.UnitTests.dll (.NETCoreApp,Version=v5.0)
16:29:40 Microsoft (R) Test Execution Command Line Tool Version 16.11.0
16:29:40 Copyright (c) Microsoft Corporation. All rights reserved.
16:29:40
16:29:40 Starting test execution, please wait...
16:29:40 A total of 1 test files matched the specified pattern.
16:29:41 An exception occurred while invoking executor 'executor://mstestadapter/v2': Could not load type 'Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior' from assembly 'Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
16:29:41 Stack trace:
16:29:41 at Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.MSTestExecutor.RunTests(IEnumerable`1 sources, IRunContext runContext, IFrameworkHandle frameworkHandle)
16:29:41 at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.RunTestsWithSources.InvokeExecutor(LazyExtension`2 executor, Tuple`2 executorUriExtensionTuple, RunContext runContext, IFrameworkHandle frameworkHandle)
16:29:41 at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.BaseRunTests.RunTestInternalWithExecutors(IEnumerable`1 executorUriExtensionMap, Int64 totalTests)
16:29:41
16:29:41
16:29:41 Test Run Failed.
16:29:41
16:29:41 Build FAILED.
16:29:41 0 Warning(s)
16:29:41 0 Error(s)
我的项目文件很简单:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0-windows</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<OutputPath>$(SolutionDir)\Bin$(Configuration)</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<OutputPath>$(SolutionDir)\Bin$(Configuration)</OutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EasyTcp" Version="4.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" />
<PackageReference Include="coverlet.collector" Version="3.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\xyz.Utilities\xyz.Utilities.csproj" />
</ItemGroup>
</Project>
我认为这与构建服务器上的 Visual Studio 版本有关。我们是 运行 Teamcity。有人知道吗?
将您的 nuget 包升级到最新版本,它应该可以解决您的问题。我认为 MSTest.TestAdapter
和 MSTest.TestFramework
.
我已经按照建议升级了,现在可以正常使用了。
谢谢菲尔
肯尼斯