dotnet核心2.1:当从xunit项目引用web项目时"发现不同版本之间的冲突"

ope*_*sas 3 .net-core asp.net-core-2.0

当我偶然发现这个奇怪的东西时,我正准备将netcore 2.0应用升级到2.1.

如果我创建一个Web项目,然后是一个引用第一个项目的xunit项目,只要我使用任何Newtonsoft.Json类,我就会收到以下错误:

/media/data/sas/devel/opt/dotnet-sdk-2.1.401/sdk/2.1.401/Microsoft.Common.CurrentVersion.targets(2110,5): 
warning MSB3277: Found conflicts between different versions of "Newtonsoft.Json" that could not be resolved.  
These reference conflicts are listed in the build log when log verbosity is set to detailed. 
[/media/data/sas/devel/apps/tmp/dotnet-error/test/test.csproj]
  test -> /media/data/sas/devel/apps/tmp/dotnet-error/test/bin/Debug/netcoreapp2.1/test.dll
Run Code Online (Sandbox Code Playgroud)

在我尝试升级的项目中,我遇到了很多这样的错误.似乎xunit项目正在使用包的diffente版本并且它们正好相似.

以下是重现错误的步骤:

$ dotnet new web -o project
$ dotnet new xunit -o test
$ cd test
$ dotnet add reference ../project/
$ dotnet clean && dotnet build
Run Code Online (Sandbox Code Playgroud)

一切正常,但如果我将它添加到project/Program.cs

    public static void Main(string[] args)
    {
        CreateWebHostBuilder(args).Build().Run();
        var s = Newtonsoft.Json.JsonConvert.SerializeObject(123);
    }
Run Code Online (Sandbox Code Playgroud)

然后我得到了上述警告.

我有办法解决这个问题吗?

BTW

$ dotnet --version
2.1.401
Run Code Online (Sandbox Code Playgroud)

ope*_*sas 15

我想我在这个迁移指南中找到了答案:

https://docs.microsoft.com/en-us/aspnet/core/migration/20_21?view=aspnetcore-2.1#rules-for-projects-targeting-the-shared-runtime

您必须Microsoft.AspNetCore.App在测试项目中添加包引用.

添加Microsoft.AspNetCore.App到MyApp.Tests 的包参考.有关更多信息,请参阅集成测试很难设置,并且可能会破坏共享框架服务.