尝试使用MSTest测试实体框架核心时System.IO.FileLoadException-为什么?

尝试使用MSTest测试实体框架核心时System.IO.FileLoadException-为什么?,mstest,entity-framework-core-3.1,Mstest,Entity Framework Core 3.1,我无法使用MSTest对实体框架核心项目进行单元测试 当我执行测试时,我总是会得到以下异常: Test method "EF_Tests.CreateDbTests.CreateDb" threw exception: System.IO.FileLoadException: Could not load file or assembly "System.Threading.Tasks.Extensions, Version=4.2.0.0, Cultur

我无法使用MSTest对实体框架核心项目进行单元测试

当我执行测试时,我总是会得到以下异常:

Test method "EF_Tests.CreateDbTests.CreateDb" threw exception: 
    System.IO.FileLoadException: Could not load file or assembly "System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

我做错了什么?



以下是我的项目结构和设置:



以下是我的项目文件的内容: Repository.csproj


netstandard2.0

EF-DB.csproj


netstandard2.0
环境足迹数据库
真的
没有一个
假的

EF测试。csproj


调试
任意CPU
{538D0C25-637D-4CDF-BDBC-26AEEB9117FD}
图书馆
性质
EF_测试
环境足迹试验
v4.7.2
512
{3AC096D0-A1C2-E12C-1390-A8335801FDB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
15
$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages
假的
单元测试
真的
满的
假的
bin\Debug\
调试;痕迹
促使
4.
没有一个
真的
bin\Release\
痕迹
促使
4.
真的
真的
{c6c34842-8e25-4bcb-a20a-6c415baa008e}
EF-DB
{b4e6eeda-2439-4674-b127-0fbf91b90a08}
存储库
2.1.2
2.1.2

我就是这么想的。您的测试csproj已全部“框架化”

您需要这样的东西:(来自.NETCoreMsTest项目)(参见下图)


netcoreapp3.1
假的
全部的
运行时间;建设;本地人;内容文件;分析仪;可传递的
全部的
运行时间;建设;本地人;内容文件;分析仪;可传递的


请显示您的csproj文件的内容。@GranadCoder:谢谢您回答我的问题。我现在添加了.csproj文件的内容。首先:非常感谢您为我指明了正确的方向!视情况而定。这还是很奇怪。。。NET框架项目(即EF测试)是消费项目;i、 e.队伍中的最后一个。另一个是支持项目,它不公开.NET标准以外的任何内容。。。我想这一定与.NET Framework和.NET Core项目的输出(即
\bin\
目录)如何捆绑引用包中的程序集有关。我不知道。但这让我想起了最初的dotnetFW说它可以处理vb6ish COM对象。我放弃了那个巫术
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>netcoreapp3.1</TargetFrameworks>
    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Chronos.Abstractions" Version="2.0.24" />
    <PackageReference Include="coverlet.msbuild" Version="2.8.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="FluentAssertions" Version="5.10.2" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
    <PackageReference Include="Moq" Version="4.13.1" />
    <PackageReference Include="MSTest.TestAdapter" Version="2.1.0" />
    <PackageReference Include="MSTest.TestFramework" Version="2.1.0" />
    <PackageReference Include="coverlet.collector" Version="1.2.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="PasswordGenerator" Version="2.0.5" />
  </ItemGroup>





</Project>