4

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.

Bahaa
  • 1,577
  • 18
  • 31
  • 1
    Doesn't the compatibility pack suffice? – Stefan Dec 05 '18 at 13:31
  • Take a look at this : https://stackoverflow.com/questions/42747977/how-do-you-multi-target-a-net-core-class-library-with-csproj . You can target multiple frameworks and assign it to items groups. – Shim-Sao Dec 05 '18 at 13:39
  • You cannot always do a complete port, that's what the warning is all about. The library may depend on native APIs, e.g. by using WinForms. In that case, the library will not work on other platforms (Linux, Mac, ...) or possibly on no platform at all (I haven't tried it and the docs are not 100% clear). – user247702 Dec 05 '18 at 13:48

1 Answers1

0

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.

Bahaa
  • 1,577
  • 18
  • 31