问题描述
是否可以在.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:
-
确保您的.NET Core项目是针对
net452 $ c $构建的c>或
)。 com / dotnet / corefx / blob / master / Documentation / architecture / net-platform-standard.md#mapping-the-net-platform-standard-to-platform>文档)。这将确保您的项目将输出.NET 4.5.2项目可以使用的二进制文件。netstandard1.2
(根据net452
Make sure your .NET Core project is building for
net452
ornetstandard1.2
(which includesnet452
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库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!