gpt4 book ai didi

c# - .NET Framework 4.6.1 应用程序在引用 .NET Standard 1.4 类库时出错

转载 作者:行者123 更新时间:2023-11-30 15:56:25 25 4
gpt4 key购买 nike

我一直在努力思考 .NET Frameworks、.NET Core 和 .NET Standard 之间的差异。根据我一直在阅读的内容,.NET Standard 是最低公分母,使用 .NET Standard 编写的库应该与使用其他框架编写的代码兼容。

但我已经创建了一个解决方案,其中包含一个使用 .NETStandard 1.4 的类库和一个使用 .NET Framework 4.6.1 的应用程序,但应用程序似乎不能使用该库.

无论应用程序在何处尝试使用类库中的类,我都会收到如下错误。

Error CS0012 The type 'IEnumerator<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.20.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

Error CS0012 The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.20.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

Error CS1579 foreach statement cannot operate on variables of type 'HtmlMonkey.HtmlNodeCollection' because 'HtmlMonkey.HtmlNodeCollection' does not contain a public definition for 'GetEnumerator'

有人可以帮助我加深对这些库的理解,以便我的应用程序可以使用我的类库吗?

最佳答案

这是一个关于 netstandard 1.4 及更低版本与 .NET 4.6.1 - 4.7 项目兼容性的已知问题。它在 .NET Standard GitHub repo 中被跟踪作为一个问题 #503 Referencing NETStandard.Library 2.0.0 in net461-net47 project and only using ns1.4 (or lower) libs doesn't work

问题描述和解决方法如下:

NETStandard.Library 2.0.0 package doesn't install netstandard1.x packages in net461-net47 projects. This is because we expected the support package to always be present on net461 and later, but when that support was implemented we dialed it back to only turn on when a netstandard1.5 or later library was referenced.

As a result installing a netstandard1.0-1.4 library in a net461-47 project and referencing NETStandard.Library 2.0.0 package will have missing dependencies.

One workaround is to use the NETStandard.Library 1.6.1 package instead. This still has the dependencies on the individual library packages to bring in the facades.

An alternative workaround is to set ImplicitlyExpandNETStandardFacades=true in the project file. This will enable all the facades for ns2.0 assemblies.

关于c# - .NET Framework 4.6.1 应用程序在引用 .NET Standard 1.4 类库时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46875551/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com