在我的构建中,我收到了类似于以下内容的警告墙:
No way to resolve conflict between "Newtonsoft.Json, Version=7.0.0.0"
and "Newtonsoft.Json, Version=6.0.0.0".
Choosing "Newtonsoft.Json, Version=7.0.0.0" arbitrarily.
Run Code Online (Sandbox Code Playgroud)
我收到以下 dll 的额外警告(重复是有意的):
Microsoft.Owin
System.Web.Http
Newtonsoft.Json
System.Net.Http.Formatting
Microsoft.Owin
Microsoft.ApplicationInsights
Run Code Online (Sandbox Code Playgroud)
以及每个警告的匹配消息:
Consider app.config remapping of assembly to solve conflict and get rid of warning.
Run Code Online (Sandbox Code Playgroud)
最后,我得到了这个冲突:
Microsoft.Common.CurrentVersion.targets Found conflicts between
different versions of the same dependent assembly.
Please set the "AutoGenerateBindingRedirects" property to true
in the project file.
Run Code Online (Sandbox Code Playgroud)
我已经阅读了我可以为这些消息找到的每个堆栈溢出和 MSDN 答案。根据这个答案,最好的解决方案是将导致冲突警告的引用更改为引用相同的版本。问题似乎是来自解决方案中 53 个项目中的一些项目的程序集链依赖于不同版本的不同程序集。我无法判断哪些项目会导致这些警告,并且绑定重定向(在我检查过的每个项目中自动生成)对警告没有影响。
我该怎么做才能解决这些构建警告?
小智 7
我遇到了这个警告并找到了解决方案。
csproj 文件中存在重复的引用。
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
Run Code Online (Sandbox Code Playgroud)
NuGet 更新后,只有第一个刷新到新版本。
当我删除第二个时,警告消失了。
它们都是相同的警告,实际上是在告诉您该怎么做。您可以清除项目中的所有引用。如果您使用的是 NuGet,这应该不是什么大问题。进入管理 NuGet 包。您应该会在列表中看到重复的包。将对旧包的引用移动到包的新版本。这是解决冲突的一种方法。
第二种方法是为所有冲突的程序集添加绑定重定向。这是 Json.net 重定向的示例。
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="7.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8721 次 |
最近记录: |