16

我正在使用 MSTest.TestAdapter 和 MSTest.TestFramework 1.2.0 版本进行我的 MS 测试单元测试。在我的本地机器(Visual Studio 2017)上,测试运行完美,但在我们的构建服务器上,我们收到以下消息:

无法加载文件或程序集“Microsoft.VisualStudio.TestPlatform.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”或其依赖项之一。该系统找不到指定的文件。

然后我用 ildasm 检查了这个程序集的引用,确实是 11.0.0.0 版本(见下文)

但是我找不到这个程序集的 v11,网上只有 nuget 上的 v14 版本:https ://www.nuget.org/packages/Microsoft.VisualStudio.TestPlatform.ObjectModel/

我也在我的机器上搜索过,我找不到v11。

所以我的问题是,为什么测试在我的机器上而不是在构建服务器上运行?

我尝试了程序集绑定但没有成功。

在此处输入图像描述

4

6 回答 6

11

您想要的 NuGet 包是 Microsoft 编写的 Microsoft.TestPlatform.ObjectModel,而不是 Christopher.Haws 编写的 Microsoft.VisualStudio.TestPlatform.ObjectModel 包。

https://www.nuget.org/packages/microsoft.testplatform.objectmodel/

Microsoft 包中包含 Microsoft.VisualStudio.TestPlatform.ObjectModel 程序集,尽管它没有以这种方式命名。我遇到了同样的错误,当我安装 Microsoft 软件包的 v11 时,它为我修复了构建服务器上的构建。

于 2018-03-07T15:59:48.293 回答
6

同样的问题,我能够安装最新版本:

Install-Package Microsoft.TestPlatform.ObjectModel -Version 15.8.0

然后将绑定重定向添加到测试项目 app.config:

    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="Microsoft.VisualStudio.TestPlatform.ObjectModel" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
                <bindingRedirect oldVersion="11.0.0.0-14.0.0.0" newVersion="15.0.0.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
于 2018-08-09T21:28:53.473 回答
2

此处推荐其他解决方法

不要反映“Microsoft.VisualStudio.TestPlatform.ObjectModel”程序集中的类型。或将 Microsoft.NET.Test.Sdk 降级到 15.3.0。

可能第二个选项不适合您,因为您使用的是 .NET 框架而不是 .NET 核心。

更多背景:

于 2019-09-06T10:51:44.890 回答
2

在另一个项目中再次遇到同样的问题后,我们再次查看并找到了解决方案。

Install-Package Microsoft.TestPlatform.ObjectModel -Version 11.0.0

但这还不够,为了确保程序集被构建服务器拾取,我们将它作为部署项添加到基础测试类中;

[DeploymentItem("Microsoft.VisualStudio.TestPlatform.ObjectModel.dll")]

现在构建服务器再次开始单元测试:-)

格茨

于 2018-03-19T10:32:16.877 回答
2

在测试输出窗口中,我遇到了这样的错误……</p>

[MSTest][Discovery][C:\Repos\Flomaster\bin\Debug\ApiTest.UnitMaintenance.dll] Failed to discover tests from assembly C:\Repos\Flomaster\bin\Debug\ApiTest.UnitMaintenance.dll. Reason:Type 'Microsoft.VisualStudio.TestPlatform.ObjectModel.Trait' in Assembly 'Microsoft.VisualStudio.TestPlatform.ObjectModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable.

我设法通过清理我的所有文件夹objbin\debug文件夹来让我的测试运行程序工作,但它又回来了,所以我看起来更深入一点,发现只需搜索Microsoft.VisualStudio.TestPlatform.ObjectModel.dll和删除任何匹配的文件就足以让测试运行程序工作

于 2020-06-08T10:33:26.233 回答
0

在错误地将 NUnit 3.0 的 NuGet 包添加到解决方案中的多个项目然后将其删除后,遇到了同样的错误。

引用没有被完全删除。我必须手动打开每个 .csproj 文件并删除对之前删除的 NuGet 包的所有引用。清理和重建后,错误消失了。

于 2019-06-25T20:12:03.727 回答