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

查看:24
本文介绍了在 .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 项目是针对 net452netstandard1.2(根据 net452 包括 net452a href="https://github.com/dotnet/corefx/blob/master/Documentation/architecture/net-platform-standard.md#mapping-the-net-platform-standard-to-platforms">文档).这将确保您的项目将输出您的 .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.

使用 dotnet pack 从 .NET Core 项目创建 nuget 包.本地或在 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天全站免登陆