可移植库导致:找不到无法解析的相同从属程序集的不同版本之间的冲突

时间:2015-11-04 13:37:39

标签: msbuild nuget portable-class-library .net-4.6 .net-core

我创建了“Contracts”可移植类库,目标是.net 4.6,ASP.NET Core和Windows 10.此库仅包含POCO类。

我有另一个名为“Communications”的项目,目标是.net 4.6并引用可移植库:

enter image description here

当我尝试构建项目时,我收到警告:

Description: Found conflicts between different versions of the same dependent assembly that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.    
Project:     Communication
File:        C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets
Line         1819

详细的构建日志在这里:buildlog.txt

为什么我会收到此警告?如何摆脱它?

以下是构建日志中可能相关的部分:

1>  Unified Dependency "System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
1>      Using this version instead of original version "1.5.0.0" in "C:\Projects\MySolution\packages\System.Net.Http.Formatting.Extension.5.2.3.0\lib\System.Net.Http.Extensions.dll" because AutoUnify is 'true'.
1>      Resolved file path is "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.Net.Http.dll".
1>      Reference found at search path location "{TargetFrameworkDirectory}".
1>          For SearchPath "C:\Projects\MySolution\packages\System.Net.Http.Formatting.Extension.5.2.3.0\lib".
1>          Considered "C:\Projects\MySolution\packages\System.Net.Http.Formatting.Extension.5.2.3.0\lib\System.Net.Http.winmd", but it didn't exist.
1>          Considered "C:\Projects\MySolution\packages\System.Net.Http.Formatting.Extension.5.2.3.0\lib\System.Net.Http.dll", but it didn't exist.
1>          Considered "C:\Projects\MySolution\packages\System.Net.Http.Formatting.Extension.5.2.3.0\lib\System.Net.Http.exe", but it didn't exist.
1>          For SearchPath "{TargetFrameworkDirectory}".
1>          Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.Net.Http.winmd", but it didn't exist.
1>      Required by "System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL".
1>      Required by "System.Net.Http.Extensions, Version=2.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL".
1>      This reference is not "CopyLocal" because it conflicted with another reference with the same name and lost the conflict.
1>      The ImageRuntimeVersion for this reference is "v4.0.30319".

...

1>  Dependency "System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes".
1>      Could not resolve this reference. Could not locate the assembly "System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
1>          For SearchPath "C:\Projects\MySolution\packages\System.Net.Http.Formatting.Extension.5.2.3.0\lib".
1>          Considered "C:\Projects\MySolution\packages\System.Net.Http.Formatting.Extension.5.2.3.0\lib\System.Core.winmd", but it didn't exist.
1>          Considered "C:\Projects\MySolution\packages\System.Net.Http.Formatting.Extension.5.2.3.0\lib\System.Core.dll", but it didn't exist.
etc...
1>          For SearchPath "{Registry:Software\Microsoft\.NETFramework,v4.6,AssemblyFoldersEx}".
1>          Considered AssemblyFoldersEx locations.
1>          For SearchPath "{AssemblyFolders}".
1>          Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\System.Core.winmd", but it didn't exist.
1>          Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\System.Core.dll", but it didn't exist.
etc...
1>          For SearchPath "{GAC}".
1>          Considered "System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes", which was not found in the GAC.
1>          For SearchPath "bin\Debug\".
1>          Considered "bin\Debug\System.Core.winmd", but it didn't exist.
1>          Considered "bin\Debug\System.Core.dll", but it didn't exist.
1>          Considered "bin\Debug\System.Core.exe", but it didn't exist.
1>      Required by "System.Net.Http.Extensions, Version=2.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL".

...

1>  There was a conflict between "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" and "mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes".
1>      "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" was chosen because it was primary and "mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes" was not.
1>      References which depend on "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" [C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\mscorlib.dll].
1>          C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\mscorlib.dll
1>            Project file item includes which caused reference "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\mscorlib.dll".
1>              System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL
1>              C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\mscorlib.dll
1>              Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL
1>          C:\Projects\MySolution\packages\System.Net.Http.Formatting.Extension.5.2.3.0\lib\System.Net.Http.Formatting.dll
1>            Project file item includes which caused reference "C:\Projects\MySolution\packages\System.Net.Http.Formatting.Extension.5.2.3.0\lib\System.Net.Http.Formatting.dll".
1>              System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL
1>          C:\Projects\MySolution\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll
1>            Project file item includes which caused reference "C:\Projects\MySolution\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll".
1>              System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL
1>              Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL
1>      References which depend on "mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes" [].
1>          C:\Projects\MySolution\packages\System.Net.Http.Formatting.Extension.5.2.3.0\lib\System.Net.Http.Extensions.dll
1>            Project file item includes which caused reference "C:\Projects\MySolution\packages\System.Net.Http.Formatting.Extension.5.2.3.0\lib\System.Net.Http.Extensions.dll".
1>              System.Net.Http.Extensions, Version=2.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL

1 个答案:

答案 0 :(得分:2)

我在.net 4.6项目中更新了nuget包System.Net.Http,警告消失了。 一般来说,很难找到这类问题的根源。通过nugget分发的.NET将来会变得混乱。