[英]Can .NET standard libraries somehow consume nuget packages, which support .NET Framework 4.6.1
I am converting a C# net461 based library to netstandard2. 我正在将基于C#net461的库转换为netstandard2。 Some of the dependencies of the library support at most net461.
该库的一些依赖性最多支持net461。 Visual Studio shows the following warning for those dependencies:
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'.
警告NU1701程序包“IKVM v8.1.5717”使用“.NETFramework,Version = v4.6.1”而不是项目目标框架“.NETStandard,Version = v2.0”进行了恢复。 This package may not be fully compatible with your project.
此软件包可能与您的项目不完全兼容。
Is there anyway to incorporate those dependencies and successfully port to netstandard2? 无论如何要将这些依赖项合并并成功移植到netstandard2?
I've looked around and tried the Microsoft.Windows.Compatibility nuget. 我环顾四周,尝试了Microsoft.Windows.Compatibility nuget。 After adding it as a further dependency to the new netstandard2 library project, the warnings are still there and the build output at 'bin/debug/netstadard2' does not contain the dlls of the nuget dependencies.
将其作为对新netstandard2库项目的进一步依赖添加后,警告仍然存在,并且'bin / debug / netstadard2'中的构建输出不包含nuget依赖项的dll。 As expected when trying the consume the library from another project, I get runtime exceptions for missing DLLs of the net461 dependencies of the netstandard2 library.
正如预期的那样,当尝试从另一个项目中使用库时,我得到netstandard2库的net461依赖项的缺失DLL的运行时异常。
After a lot of experiments and search, I found out that the problem is two-fold: 经过大量的实验和搜索,我发现问题是双重的:
In my case, problem #1 was solved by including the windows compatibility pack, which includes the extra APIs my net461 dependencies used. 在我的例子中,问题#1通过包含windows兼容包来解决,其中包括我使用的net461依赖项的额外API。 But because of problem #2, I still got runtime exceptions.
但由于问题#2,我仍然遇到运行时异常。
Problem #2 was solved by making sure all imports use the PackageReference
style, which pulls transitive dependencies. 问题#2通过确保所有导入使用
PackageReference
样式来解决,该样式提取了传递依赖性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.