.NET 标准库能否以某种方式使用支持 .NET Framework 4.6.1 的 nuget 包

Can .NET standard libraries somehow consume nuget packages, which support .NET Framework 4.6.1

我正在将基于 C# net461 的库转换为 netstandard2。该库的一些依赖项最多支持 net461。 Visual Studio 对这些依赖项显示以下警告:

Warning NU1701 Package 'IKVM v8.1.5717' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.

有没有办法合并这些依赖项并成功移植到 netstandard2?

我环顾四周并尝试了 Microsoft.Windows.Compatibility nuget。将其作为新 netstandard2 库项目的进一步依赖项添加后,警告仍然存在,'bin/debug/netstadard2' 处的构建输出不包含 nuget 依赖项的 dll。正如预期的那样,在尝试使用另一个项目的库时,我得到了运行时异常,因为缺少 netstandard2 库的 net461 依赖项的 DLL。

经过大量的实验和搜索,我发现问题有两个方面:

  1. net461 依赖项具有 netstandard 2.0 未涵盖的 API, 这导致了运行时错误。
  2. 作为传递依赖项,net461 依赖项的 DLL 未包含在构建过​​程中。

就我而言,问题 #1 已通过包含 windows 兼容包解决,其中包含我的 net461 依赖项使用的额外 API。但是由于问题 #2,我仍然遇到运行时异常。

问题 #2 通过确保所有导入都使用 PackageReference 样式来解决,这会拉取传递依赖项。