当我偶然发现这个奇怪的事情时,我正在将 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);
}
然后我得到了上述警告。
我有办法解决这个问题吗?
顺便提一句
$ dotnet --version
2.1.401
最佳答案
我想我在这个 migration guide 中找到了答案:
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
的包引用在测试项目中。
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.
关于.net-core - dotnet 核心 2.1 : "Found conflicts between different versions of" when referencing a web project from an xunit project,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52072663/