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
问题描述
当我偶然发现这个奇怪的东西时,我正在将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
推荐答案
我想我在迁移指南:
您必须在测试项目中添加对 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屋!