简体   繁体   English

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

[英]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: 经过大量的实验和搜索,我发现问题是双重的:

  1. The net461 dependencies had APIs not covered by netstandard 2.0, which caused runtime errors. net461依赖项具有netstandard 2.0未涵盖的API,这会导致运行时错误。
  2. Being transitive dependencies, the DLLs of the net461 dependencies were not included during build. 作为传递依赖,构建期间不包括net461依赖项的DLL。

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.

相关问题 在NET Standard项目中消耗.NET 4.6.1 NuGet软件包的问题(bin中缺少dll) - Problem consuming .NET 4.6.1 NuGet packages in NET Standard project ( missing dlls in bin ) .NET Core Web应用程序可以使用.NET Framework类库吗? - Can a .NET Core Web app consume .NET Framework class libraries? Nuget package 创建 - Class 库以 Z303CB0EF9EDB9082D61BBBE5625D972AZ41 为目标框架不正确。 - Nuget package creation - Class library that targets .NET framework 4.6.1 can not target correct framework NuGet 包在 a.Net Standard 2.0 dll 被.Net Framework 和.Net Core 使用 - NuGet packages in a .Net Standard 2.0 dll used by both .Net Framework and .Net Core 无法将NUGET hdf5-v120-complete安装到具有框架4.6.1的.NET项目 - can't install NUGET hdf5-v120-complete to .NET project with framework 4.6.1 我可以使用在.NET Standard 2.0中为.NET Framework编写的包吗? - Can I use packages written for .NET Framework in .NET Standard 2.0? 更新到.NET Standard 2.0 Nuget软件包 - Updating to .NET Standard 2.0 Nuget packages 搜索.NET Core或标准NuGet包 - Search for .NET Core or Standard NuGet packages 对于.Net Core 2.1项目,为什么Nuget恢复.Net 4.6.1包? - For a .Net Core 2.1 project, Why does Nuget restores .Net 4.6.1 packages? 假货和 .net Framework 4.6.1 和系统 - Fakes and .net Framework 4.6.1 and System
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM