将.NETFramework 4.5 dll添加到.NETCore项目 [英] Add .NETFramework 4.5 dll to .NETCore project

查看:690
本文介绍了将.NETFramework 4.5 dll添加到.NETCore项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个先前生成的DLL,其中包含一些我想在.NETCore项目中重用的企业代码。但是,由于原始DLL是使用.NETFramework 4.5创建和编译的,因此我无法直接将dll作为引用添加。

I have a previously generated DLL with some enterprise code that I would like to reuse in a .NETCore project. However, since the original DLL was created and compiled using .NETFramework 4.5 I am not able to directly add the dll as a reference.

我创建了一个包含dll的nuget程序包如此处所示。之后,我可以将这样的包添加到项目中。但是,我遇到以下错误:

I created a nuget package containing my dll as shown here. After that, I am able to add such package to the project. However, I am having the following error:


依赖性MyAssembly.dll不支持框架
.NETCoreApp,Version = v1.0

"The dependency MyAssembly.dll does not support framework .NETCoreApp,Version=v1.0"

我已经尝试引用.NETCore.Portable.Compatibility,但我认为这不是正确的方法。如何在代码中使用此dll?
这是添加Nuget包后我的project.json的样子。

I have already tried referencing .NETCore.Portable.Compatibility but I dont think that is the right way to go. How can I use this dll on my code? This is what my project.json looks like after adding the Nuget package.

{
  "version": "1.0.0-*",

  "dependencies": {
    "MyAssembly.dll": "1.0.0",
    "Microsoft.EntityFrameworkCore": "1.0.0",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
    "Microsoft.NETCore.Portable.Compatibility": "1.0.1",
    "NETStandard.Library": "1.6.0"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [ "dnxcore50", "portable-net451+win8" ]
    }
  }
}


推荐答案

您可以在.netcore类库的项目json文件中添加多个框架。默认情况下,您将拥有.net核心框架。只需添加逗号并添加所需的.net框架即可。

You can add more than one frameworks in project json file in your .netcore class library. By default you will have .net core framework. Just add comma and add your required .net framework.

{
    "version": "1.0.0-*",
    "frameworks": {
        "netstandard1.6": {
            "dependencies": {
                "NETStandard.Library": "1.6.0"
            },
            "imports": "dnxcore50"
        },
        "net45": {
            "dependencies": {},
            "imports": "net452"
        }
    }
}

这篇关于将.NETFramework 4.5 dll添加到.NETCore项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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