在.NET 4.5.2中引用.NET Core库 [英] Referencing .NET Core library in .NET 4.5.2

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

问题描述

是否可以在.NET 4.5.2项目中引用.NET Core库?我正在使用最新的.NET Core rc,并且想对我的WPF项目和.NET Core Web API使用相同的库。如果要添加对项目的引用,则会显示以下窗口:

Is it possible to reference a .NET Core library in a .NET 4.5.2 project? I'm using the latest rc of .NET Core and want to use the same library for my WPF project and my .NET Core Web API. If I want to add the reference to my project this window is shown:

我还尝试将WPF项目升级到4.6.1,但这没有任何改变。

I also tried to upgrade my WPF project to 4.6.1 but this doesn't changes anything.

更新

Core 2.0现在可以使用

Update
It is now possible with Core 2.0

推荐答案

截至目前(2016年6月),有两个所需步骤:

As of now (June 2016), there are two steps required:


  1. 确保您的.NET Core项目是针对 net452 netstandard1.2 (根据net452 )。 com / dotnet / corefx / blob / master / Documentation / architecture / net-platform-standard.md#mapping-the-net-platform-standard-to-platform>文档)。这将确保您的项目将输出.NET 4.5.2项目可以使用的二进制文件。

  1. Make sure your .NET Core project is building for net452 or netstandard1.2 (which includes net452 according to the docs). This will ensure that your project will output a binary that your .NET 4.5.2 project can use.

使用以下方法从.NET Core项目中创建一个nuget包: dotnet包。在本地 或在MyGet上托管。在您的.NET 4.5.2应用程序中引用此程序包将提取正确的二进制文件!

Create a nuget package from your .NET Core project with dotnet pack. Host this locally or on MyGet. Referencing this package in your .NET 4.5.2 application will pull in the correct binary!

Visual Studio显然是将来可以直接从csproj项目中引用.NET Core项目,但就目前而言,步骤2是我发现的最佳解决方法。

Visual Studio will apparently be able to directly reference .NET Core projects from csproj projects in the future, but for now, step 2 is the best workaround I've found.

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

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