在.NET 4.5.2控制台应用程序中使用.NET Core库 [英] Using .NET Core library in .NET 4.5.2 console application

查看:406
本文介绍了在.NET 4.5.2控制台应用程序中使用.NET Core库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个项目:一个项目建立在.NET Core上,另一个项目建立在普通的.NET Framework 4.5.2。上。



我想知道如何在.NET控制台应用程序中使用.NET Core cass库。



这是我的project.json:

  {
版本: 1.0.0- *,

依赖关系:{
NETStandard.Library: 1.6.0,
NLog.Web .AspNetCore: 4.3.0,
System.Xml.XmlSerializer: 4.0.11
},

frameworks:{
netstandard1.6:{
进口: dnxcore50
},
net452:{}
}
}

我试图将项目作为常规参考。但是,在重新构建解决方案之后,控制台应用程序仍然没有将.NET Core库作为参考。

解决方案

Visual Studio 2017可以本机执行此操作; Visual Studio 2015不能(自Update 3起)。这些工具中的许多错误和问题已通过.NET Core工具的稳定版本(在VS 2017中得到了解决)得以修复和完成。



您可以通过两种解决方法如果您仍在使用VS 2015,请立即使用:




  • 使用 dotnet包为类库生成一个NuGet包。由于您在project.json中定位了 net452 ,因此它将与.NET Framework 4.5.2项目兼容。您可以将其托管在本地Feed 上,并将其安装在控制台应用程序项目中。 / p>


  • 手动引用编译库时生成的DLL。它应该位于 bin / net452 / YourLibrary.dll 。这不是一个很好的解决方案,因为它易碎并且容易折断。



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.

解决方案

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.

这篇关于在.NET 4.5.2控制台应用程序中使用.NET Core库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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