Code reuse of .NET 4.0 DLL (that uses Nuget packages) with .NET CORE

▼魔方 西西 提交于 2019-12-12 04:07:55

问题


I spent a few days writing a class library of .DLL functions in .NET 4.0.

Now I want to call it from an AWS Lambda function using .NET Core. Apparently, we cannot reference from CORE to .NET Framework; get this error:

In my class library, I used every Nuget package I could to save time and make my code small. So even if I convert my class library to CORE, I would have to now rewrite each of the Nuget packages?

Seems like we really don't have code re-use here. Am I missing some shortcut here, or it's just going to be a big pain? If each Nuget is open source, then I would have to get the code, then build a .CORE version of it?

I read this Q/A but didn't really give any solution yet: Converting a .Net dll to a .Net Core dll


回答1:


Most of the nuget packages are netstandard (1.x/2.x) compliant so there is big chance that you can use them in your project if you convert your project to .NET Standard library. For example Autofac is compatible with .NET Framework 4.5 and also with .NET Standard 1.1 (.NET Standard Library >= 1.6).

From the screenshot we can see that your project is not .NET Standard compliant. The difference is that you have used .NET Framework template for project like:

While you should be using .NET Standard template:

If your project is not using some windows native functions there is high probability that you can just convert it to .NET Standard project with little or no change at all.

Here is how to create new project that is .NET Standard compliant: Also, from screenshot I can see that you are targeting .NET Core 1.0 so you have to make sure that your project is targeting correct .NET Standard version (I know that this can be confusing now). Here is a list of .NET Framework / .NET Core compatibility with .NET Standard. For .NET Core 1.0 your library should be targeting .NET Standard 1.6:




回答2:


i believe that you can also create a nuget package from your existing DLL, then it works to :)

(if i am not mistaken, not 100% sure though)



来源:https://stackoverflow.com/questions/46758443/code-reuse-of-net-4-0-dll-that-uses-nuget-packages-with-net-core

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!