如何找出 Nuget 包中的主要问题

How to figure out the main issue in a Nuget Package

我最近更新了我的包,我开始在一些项目中收到这个奇怪的警告。我无法解决它:

Found conflicts between different versions of "System.Runtime.CompilerServices.Unsafe" that could not be resolved.
There was a conflict between "System.Runtime.CompilerServices.Unsafe, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
    "System.Runtime.CompilerServices.Unsafe, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was chosen because it was primary and "System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was not.
    References which depend on "System.Runtime.CompilerServices.Unsafe, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [C:\Users[=10=]00\.nuget\packages\system.runtime.compilerservices.unsafe.0.0\ref\net461\System.Runtime.CompilerServices.Unsafe.dll].
        C:\Users[=10=]00\.nuget\packages\system.runtime.compilerservices.unsafe.0.0\ref\net461\System.Runtime.CompilerServices.Unsafe.dll
          Project file item includes which caused reference "C:\Users[=10=]00\.nuget\packages\system.runtime.compilerservices.unsafe.0.0\ref\net461\System.Runtime.CompilerServices.Unsafe.dll".
            C:\Users[=10=]00\.nuget\packages\system.runtime.compilerservices.unsafe.0.0\ref\net461\System.Runtime.CompilerServices.Unsafe.dll
    References which depend on "System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [].
        C:\Users[=10=]00\.nuget\packages\system.memory.5.4\lib\net461\System.Memory.dll
          Project file item includes which caused reference "C:\Users[=10=]00\.nuget\packages\system.memory.5.4\lib\net461\System.Memory.dll".
            C:\Users[=10=]00\.nuget\packages\system.memory.5.4\lib\net461\System.Memory.dll
            C:\Users[=10=]00\.nuget\packages\system.collections.immutable.0.0\lib\net461\System.Collections.Immutable.dll
            C:\Users[=10=]00\.nuget\packages\nito.disposables.2.1\lib\net461\Nito.Disposables.dll
            C:\Users[=10=]00\.nuget\packages\nito.asyncex.context.1.2\lib\net461\Nito.AsyncEx.Context.dll
            C:\Users[=10=]00\.nuget\packages\nito.asyncex.coordination.1.2\lib\net461\Nito.AsyncEx.Coordination.dll
            C:\Users[=10=]00\.nuget\packages\nito.asyncex.oop.1.2\lib\net461\Nito.AsyncEx.Oop.dll
            C:\Users[=10=]00\.nuget\packages\nito.asyncex.tasks.1.2\lib\net461\Nito.AsyncEx.Tasks.dll
            C:\Users[=10=]00\.nuget\packages\nito.asyncex.interop.waithandles.1.2\lib\net461\Nito.AsyncEx.Interop.WaitHandles.dll
            C:\Users[=10=]00\.nuget\packages\nito.cancellation.1.2\lib\net461\Nito.Cancellation.dll
        C:\Users[=10=]00\.nuget\packages\system.threading.tasks.extensions.6.0-preview.18571.3\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll
          Project file item includes which caused reference "C:\Users[=10=]00\.nuget\packages\system.threading.tasks.extensions.6.0-preview.18571.3\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll".
            C:\Users[=10=]00\.nuget\packages\system.threading.tasks.extensions.6.0-preview.18571.3\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll
            C:\Users[=10=]00\.nuget\packages\utf8json.3.7\lib\net47\Utf8Json.dll
            C:\Users[=10=]00\.nuget\packages\easy.logger.extensions.5.0\lib\net45\Easy.Logger.Extensions.dll Focus.Tests.LogicTester

我如何破译这里的实际问题是什么?是否有内部依赖于特定版本 DLL 但该 DLL 也直接添加到较新版本的包?

简而言之,您依赖于同一 DLL 的两个不同版本。下面的细分,但是 TL;DR,您应该能够通过将 PackageReference 更新到 System.Runtime.CompilerServices.Unsafe 到版本 6.0.0.

来解决这个问题

如果您不直接调用它,请考虑删除 PackageReference,因为它应该通过下面列出的其他引用传递地添加。

如果您没有此包的 PackagerReference,添加一个(使用版本 6.0.0)将使它成为主要引用,从而再次将所有内容对齐到同一版本。

错误信息细目:

Found conflicts between different versions of "System.Runtime.CompilerServices.Unsafe" that could not be resolved.
There was a conflict between "System.Runtime.CompilerServices.Unsafe, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".

编译器根据您引用它的直接程度(与引用它的依赖项之一相反)来选择一个:

"System.Runtime.CompilerServices.Unsafe, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was chosen because it was primary and "System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was not.

5.0 版本被引用:

References which depend on "System.Runtime.CompilerServices.Unsafe, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [C:\Users[=12=]00\.nuget\packages\system.runtime.compilerservices.unsafe.0.0\ref\net461\System.Runtime.CompilerServices.Unsafe.dll].
    C:\Users[=12=]00\.nuget\packages\system.runtime.compilerservices.unsafe.0.0\ref\net461\System.Runtime.CompilerServices.Unsafe.dll

项目中对 5.0 文件创建此运行时依赖项的项目似乎是它本身,即您直接引用它:

Project file item includes which caused reference "C:\Users[=13=]00\.nuget\packages\system.runtime.compilerservices.unsafe.0.0\ref\net461\System.Runtime.CompilerServices.Unsafe.dll".
  C:\Users[=13=]00\.nuget\packages\system.runtime.compilerservices.unsafe.0.0\ref\net461\System.Runtime.CompilerServices.Unsafe.dll

这些依赖项引用了 6.0 版本:

References which depend on "System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [].
    C:\Users[=14=]00\.nuget\packages\system.memory.5.4\lib\net461\System.Memory.dll
      ...
    C:\Users[=14=]00\.nuget\packages\system.threading.tasks.extensions.6.0-preview.18571.3\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll
      ...

这些是通过其他包间接引用的:

Project file item includes which caused reference "C:\Users[=15=]00\.nuget\packages\system.memory.5.4\lib\net461\System.Memory.dll".
  C:\Users[=15=]00\.nuget\packages\system.memory.5.4\lib\net461\System.Memory.dll
  C:\Users[=15=]00\.nuget\packages\system.collections.immutable.0.0\lib\net461\System.Collections.Immutable.dll
  C:\Users[=15=]00\.nuget\packages\nito.disposables.2.1\lib\net461\Nito.Disposables.dll
  C:\Users[=15=]00\.nuget\packages\nito.asyncex.context.1.2\lib\net461\Nito.AsyncEx.Context.dll
  C:\Users[=15=]00\.nuget\packages\nito.asyncex.coordination.1.2\lib\net461\Nito.AsyncEx.Coordination.dll
  C:\Users[=15=]00\.nuget\packages\nito.asyncex.oop.1.2\lib\net461\Nito.AsyncEx.Oop.dll
  C:\Users[=15=]00\.nuget\packages\nito.asyncex.tasks.1.2\lib\net461\Nito.AsyncEx.Tasks.dll
  C:\Users[=15=]00\.nuget\packages\nito.asyncex.interop.waithandles.1.2\lib\net461\Nito.AsyncEx.Interop.WaitHandles.dll
  C:\Users[=15=]00\.nuget\packages\nito.cancellation.1.2\lib\net461\Nito.Cancellation.dll
...
Project file item includes which caused reference "C:\Users[=15=]00\.nuget\packages\system.threading.tasks.extensions.6.0-preview.18571.3\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll".
  C:\Users[=15=]00\.nuget\packages\system.threading.tasks.extensions.6.0-preview.18571.3\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll
  C:\Users[=15=]00\.nuget\packages\utf8json.3.7\lib\net47\Utf8Json.dll
  C:\Users[=15=]00\.nuget\packages\easy.logger.extensions.5.0\lib\net45\Easy.Logger.Extensions.dll Focus.Tests.LogicTester