简体   繁体   中英

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. Some of the dependencies of the library support at most net461. Visual Studio shows the following warning for those dependencies:

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.

Is there anyway to incorporate those dependencies and successfully port to netstandard2?

I've looked around and tried the 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. 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.

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.
  2. Being transitive dependencies, the DLLs of the net461 dependencies were not included during build.

In my case, problem #1 was solved by including the windows compatibility pack, which includes the extra APIs my net461 dependencies used. But because of problem #2, I still got runtime exceptions.

Problem #2 was solved by making sure all imports use the PackageReference style, which pulls transitive dependencies.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM