.net core dotnet core 2.1:“;发现“的不同版本之间存在冲突”;从xunit项目引用web项目时

.net core dotnet core 2.1:“;发现“的不同版本之间存在冲突”;从xunit项目引用web项目时,.net-core,asp.net-core-2.0,.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

我在将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
在我试图升级的项目中,我遇到了很多这样的错误。xunit项目似乎正在使用不同版本的包,并且它们是共线的

以下是重现错误的步骤:

$ dotnet new web -o project
$ dotnet new xunit -o test
$ cd test
$ dotnet add reference ../project/
$ dotnet clean && dotnet build
一切正常,但如果我把它添加到project/Program.cs中

    public static void Main(string[] args)
    {
        CreateWebHostBuilder(args).Build().Run();
        var s = Newtonsoft.Json.JsonConvert.SerializeObject(123);
    }
然后我得到了前面提到的警告

我有办法解决这个问题吗

顺便说一句


我想我找到了答案:

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

将Microsoft.AspNetCore.App的包引用添加到MyApp.Tests。 有关详细信息,请参阅


我还必须先清理我的项目,然后再重新构建。
$ dotnet --version
2.1.401