Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
334 views
in Technique[技术] by (71.8m points)

c# - Add .NETFramework 4.5 dll to .NETCore project

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.

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:

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

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" ]
    }
  }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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"
        }
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...