无法从程序集'Microsoft.AspNetCore.Hosting,Version = 3.0.0.0加载类型'Context'

时间:2019-08-01 05:07:23

标签: .net-core upgrade preview

在使用.netcore 2.2 的情况下,升级到.netcore 3.0

这是我们在运行单元测试时遇到的错误:

  

“无法从程序集'Microsoft.AspNetCore.Hosting,Version = 3.0.0.0中加载类型'Context'”

1 个答案:

答案 0 :(得分:5)

这些步骤适用于我们的项目:

  1. 删除旧包
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Cors" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.2.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
  1. 安装
    Microsoft.AspNetCore.Mvc.Testing 3.0.0-preview7.19365.7
  1. 更新Startup.cs
    .AddApplicationPart(Assembly.Load("YourProjectControllerNamespace"))