dotnet core 2.1:“发现不同版本之间的冲突”。从xunit项目引用Web项目时 [英] dotnet core 2.1: "Found conflicts between different versions of" when referencing a web project from an xunit project

查看:375
本文介绍了dotnet core 2.1:“发现不同版本之间的冲突”。从xunit项目引用Web项目时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我偶然发现这个奇怪的东西时,我正在将netcore 2.0应用程序升级到2.1。

I was on my way to upgrade a netcore 2.0 app to 2.1 when I stumbled upon this strange thing.

如果我创建一个Web项目,然后创建一个xunit当我使用任何Newtonsoft.Json类时,引用第一个的项目就会出现以下错误:

If I create a web project, and then a xunit project referencing the first one, as soon as I use any Newtonsoft.Json class I get the following error:

/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项目正在使用不同版本的软件包,并且它们相互冲突。

In the project I was trying to upgrade I get lots of errors like this. It seems like the xunit project is using diffente versions of the packages and that they colide.

以下是重现错误的步骤:

These are the steps to reproduce the error:

$ dotnet new web -o project
$ dotnet new xunit -o test
$ cd test
$ dotnet add reference ../project/
$ dotnet clean && dotnet build

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

and everything works ok, but if I add this to project/Program.cs

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

然后我收到上述警告。

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

I there some way to work this out?

BTW

$ dotnet --version
2.1.401


推荐答案

我想我在迁移指南

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

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

You have to add a package reference to Microsoft.AspNetCore.App in the test project.


Microsoft.Asp添加程序包引用NetCore.App 到MyApp.Tests。
有关更多信息,请参见集成测试很难设置,
可能会损坏

Add a package reference for Microsoft.AspNetCore.App to MyApp.Tests. For more information, see Integration testing is hard to set up and may break on shared framework servicing.

这篇关于dotnet core 2.1:“发现不同版本之间的冲突”。从xunit项目引用Web项目时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆