Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referencing .NET Core library in .NET 4.5.2

Tags:

.net

.net-core

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:

enter image description here

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

Update
It is now possible with Core 2.0

like image 253
Christian Klemm Avatar asked Jun 28 '16 19:06

Christian Klemm


People also ask

Can we use .NET Core library in .NET Framework?

ASP.NET Web Forms applications: ASP.NET Web Forms are only available in . NET Framework. ASP.NET Core cannot be used for ASP.NET Web Forms.

How do I add a reference to .NET Core library?

Add Class Library Reference To use a class library in your application, you must add a reference to the library to access its functionality. Right click on the project name of your console app in Solution Explorer and select Add ->Reference option.

Can you reference .NET Core from .NET standard?

NET Core wouldn't be able to reference a . NET Standard project.


1 Answers

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

  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.

  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 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.

like image 125
Nate Barbettini Avatar answered Sep 22 '22 07:09

Nate Barbettini