不应该兼容的.NET标准程序集? [英] Incompatible .NET Standard assemblies that should have been compatible?

查看:111
本文介绍了不应该兼容的.NET标准程序集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.NET Standard 2.0 DLL项目。

I have a .NET Standard 2.0 DLL project.

除了 NETStandard.Library 2.0.1 ,它没有其他引用,一切都很好。

It has no other references, apart from NETStandard.Library 2.0.1 and all is fine.

它已被WPF应用程序引用,并且一切正常。

It is referenced by a WPF application and everything seems to work fine.

我为 System.Collections.Immutable 1.5添加了一个nuget包。 0 到DLL项目,解决方案资源管理器的 Dependencies 根目录上会出现一个黄色的感叹号。 (嗯...我现在看到即使删除了这个程序包,感叹仍然存在,但是我猜想这是一个VS错误,因为在添加该库之前,一切似乎都可以正常工作)

Once I add a nuget package for System.Collections.Immutable 1.5.0 to the DLL project, a yellow exclamation mark appears on the Dependencies root of the Solution Explorer. (Hm... I now see that the exclamation remains even after I remove this package, but I guess this is a VS bug since everything seemed to work just fine before adding this library)

同时拥有这两个软件包,一切正常,但是当我尝试使用 ImmutableDictionary ,我得到以下提示:

Having both packages, everything builds fine, but when I try to use the ImmutableDictionary, I get this:


System.IO.FileNotFoundException:'无法加载文件或程序集 System.Collections.Immutable,版本= 1..2.3.0,文化=中性,PublicKeyToken = b03f5f7f11d50a3a或其依赖项之一。系统找不到指定的文件。'

System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Collections.Immutable, Version=1.2.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'

看着nuget包,我知道这两个文件应该一起工作,因为(我的理解)'System.Collections.Immutable`库表示它支持.NET标准2.0。

Looking at the nuget packages, I understand that those two should work together, since (from my understanding) the 'System.Collections.Immutable` library says it supports .NET standard 2.0.

我对.NET Standard世界非常陌生。

I am very new to the .NET Standard world.

查看系统的公钥令牌我的主应用程序 bin 文件夹中的.Collections.Immutable.dll 我看到它确实是 b03f5f7f11d50a3a 符合预期。但是版本不同。

Looking at the public key token of the System.Collections.Immutable.dll in my main app's bin folder I see that it was indeed b03f5f7f11d50a3a as expected. However the version is different.

< img src = https://i.stack.imgur.com/I5JI9.png alt = Hm ...>

通常,在旧的.NET中,我会尝试在应用程序的配置文件中添加程序集重定向。但是在这里这样做似乎没有任何区别。将其添加到引用DLL的WPF应用程序中:

Normally, in the old .NET I would try to add an assembly redirection in the app's config file. But doing this here does not seem to make any difference. Adding this into my WPF app that references the DLL:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

...将此例外更改为:

... changes the exception to this:


System.IO.FileNotFoundException:'无法加载文件或程序集'System.Collections.Immutable,Version = 4.0.11.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其依赖性之一。系统找不到指定的文件。'

System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Collections.Immutable, Version=4.0.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'

内部异常

FileNotFoundException:无法加载文件或程序集' System.Collections.Immutable,版本== 1.2.3.0,文化=中性,PublicKeyToken = b03f5f7f11d50a3a'或其依赖项之一。系统找不到指定的文件。

FileNotFoundException: Could not load file or assembly 'System.Collections.Immutable, Version=1.2.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

这是怎么回事?
我不能同时使用这两个nuget包吗?

What is going on here? Can't I use those two nuget packages together?

更新:

我现在注意到我获得的DLL版本来自 System.Collections.Concurrent.dll ,而我对 System感兴趣。在我的bin文件夹中找不到的Collections.Immutable.dll ...
我什至没有找到nuget软件包存储在解决方案中的位置。

I now notice that the DLL version that I got was from System.Collections.Concurrent.dll, while I am interested at System.Collections.Immutable.dll which is nowhere to be found on my bin folders... I haven't even found where the nuget packages are stored in my solution.

更新2:

事实证明,当我创建一个新的时,会得到完全相同的行为具有类似设置的解决方案(完整框架控制台应用程序引用.NET Standard 2 DLL)。

It turns out that I get the exact same behavior when I create a new solution with similar setup (Full framework console app referencing .NET Standard 2 DLL).

按照@LasseVågsætherKarlsen的建议,我已从此处下载了nuget包 https://www.nuget.org/packages/System.Collections.Immutable ,已提取取出正确的DLL,并将其放在我的bin文件夹中。然后控制台应用程序开始工作。

Following @Lasse Vågsæther Karlsen's advice, I have downloaded the nuget package from here https://www.nuget.org/packages/System.Collections.Immutable, extracted the correct DLL out of it, and placed it in my bin folder. Then the console app worked.

我正在使用Visual Studio的15.7.1版本。我不确定在最新的15.7.2版本中已对此进行了哪些更改...

I am using the 15.7.1 version of Visual Studio. I am not sure what are the changes are of this being fixed in the latest 15.7.2 version...

您可以尝试从以下位置下载我的可验证示例:

You can try my verifiable example by downloading it from here: https://mega.nz/#!YZMwGABD!eHHxvNdO59l2m5ZlHMG1vvqCd-GHv3EVckR-9htDojs

推荐答案

有2种解决方法:

1-更新ConsoleApp1的项目文件以将该文件包含在属性组中

1 - Update the project file for the ConsoleApp1 to include this in the property group

<RestoreProjectStyle>PackageReference</RestoreProjectStyle>

2-添加对 System.Collections.Immutable 直接在ConsoleApp1
项目中。

2 - Add a reference to System.Collections.Immutable directly in the ConsoleApp1 project.

这是一个已知问题,其中使用项目到项目引用和NuGet程序包引用不会自动流动正确引用。正在此处进行跟踪,但是其中一种变通办法应该取消阻止。

This is a known issue where using Project-to-Project references and NuGet package references does not automatically flow the references correctly. This is being tracked here but one of these workarounds should unblock this.

这篇关于不应该兼容的.NET标准程序集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆