.NET CORE的.NET 4.0 DLL(使用Nuget包)的代码重用 [英] Code reuse of .NET 4.0 DLL (that uses Nuget packages) with .NET CORE

查看:271
本文介绍了.NET CORE的.NET 4.0 DLL(使用Nuget包)的代码重用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了几天时间在.NET 4.0中编写.DLL函数的类库.

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

现在,我想使用.NET Core从AWS Lambda函数调用它. 显然,我们不能从CORE引用.NET Framework.出现此错误:

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:

在我的类库中,我使用了所有可以节省时间并减小代码长度的Nuget包.因此,即使将我的类库转换为CORE,我现在也必须重写每个Nuget包吗?

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?

似乎我们真的没有在这里重复使用代码.我是否在这里缺少捷径,否则将是一个很大的痛苦?如果每个Nuget是开源的,那么我将必须获取代码,然后构建它的.CORE版本?

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

推荐答案

大多数nuget软件包都符合netstandard(1.x/2.x),因此如果转换,很有可能在项目中使用它们您的项目到.NET标准库.例如, Autofac 与.NET Framework 4.5和.NET Standard 1.1(. NET标准库> = 1.6).

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).

从屏幕截图中,我们可以看到您的项目不符合.NET Standard.区别在于您已将.NET Framework模板用于以下项目:

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:

虽然您应该使用.NET Standard模板:

While you should be using .NET Standard template:

如果您的项目未使用某些Windows本机功能,则很有可能只需很少或根本没有任何更改就可以将其转换为.NET Standard项目.

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.

以下是创建符合.NET Standard的新项目的方法: 另外,从屏幕截图中,我可以看到您的目标是.NET Core 1.0,因此必须确保您的项目的目标是正确的.NET Standard版本(我知道这现在可能会令人困惑). 此处是.NET Framework/.NET Core的列表与.NET Standard的兼容性. 对于.NET Core 1.0,您的库应针对.NET Standard 1.6:

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:

这篇关于.NET CORE的.NET 4.0 DLL(使用Nuget包)的代码重用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆