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

查看:32
本文介绍了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);
    }

然后我收到了上述警告.

Then I get the afforementioned warning.

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

I there some way to work this out?

顺便说一句

$ dotnet --version
2.1.401

推荐答案

我想我在这个 迁移指南:

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 的包引用.

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

Microsoft.AspNetCore.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天全站免登陆