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

查看:81
本文介绍了将 .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,版本=v1.0"

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

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

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天全站免登陆