Using .NET Core library in .NET 4.5.2 console application

假装没事ソ 提交于 2019-12-12 11:33:26

问题


I have two projects: one project is built on .NET Core and the other one is built on normal .NET Framework 4.5.2.

I want to know how I can use my .NET Core cass library in my .NET Console Application.

Here is my project.json:

{
  "version": "1.0.0-*",

  "dependencies": {
    "NETStandard.Library": "1.6.0",
    "NLog.Web.AspNetCore": "4.3.0",
    "System.Xml.XmlSerializer": "4.0.11"
  },

  "frameworks": {
    "netstandard1.6": {
      "imports": "dnxcore50"
    },
    "net452": {}
  }
}

I tried to include the project as a normal reference. But after re-building the solution the Console Application still doesn't get the .NET Core library as a reference.


回答1:


Visual Studio 2017 can do this natively; Visual Studio 2015 cannot (as of Update 3). A lot of these tooling bugs and issues are being fixed and finalized with the stable version of the .NET Core tooling, expected with VS 2017.

There are two workarounds you can use today, if you are still using VS 2015:

  • Use dotnet pack to produce a NuGet package for the class library. Since you target net452 in your project.json, it will be compatible with a .NET Framework 4.5.2 project. You can host it on a local feed and install it in your console application project.

  • Manually reference the DLL that's produced when you compile the library. It should be at bin/net452/YourLibrary.dll. This isn't a great solution because it's brittle and can break easily.



来源:https://stackoverflow.com/questions/41937276/using-net-core-library-in-net-4-5-2-console-application

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