Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't reference .NET Core class library in Universal Windows or WPF app

I have a .NET Core class library, targeting .NET Standard 1.6.

I want to make a small Windows app with a GUI I can use to test various capabilities of my class library. At this point, I don't particularly care if it's WPF or Universal.

I've tried adding both project types (WPF and UWP) to the solution using the available templates in Visual Studio 2017 RC, but when I try to build either I get compatibility errors e.g.

.NETStandard,Version=v1.6... cannot be referenced by a project that targets UAP,Version=v10.0.10586

.NETStandard,Version=v1.6... cannot be referenced by a project that targets .NETFramework,Version=v.4.5.2

Which makes sense, but I can't figure out how to make any sort of GUI app at all that can use a .NET Core class library.

like image 601
user888734 Avatar asked Feb 27 '17 17:02

user888734


People also ask

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

One method of adding references to your library is by typing it directly in the project. json file. As you can see that we have added some references under the dependencies section as shown in the following code. Let us now save this file and you will see that references are added to your library now.

Can I use .NET core with WPF?

From the recent 17.2 release, you can run existing WPF and WinForms product showcase demos in both . NET Core and . NET Framework.

Can we use .NET core library in .NET framework?

once you add the requisite framework and build, you can reference the . NET CORE project from your . NET 4.6 application directly.

How do I use .NET standard library in .NET core?

Open Visual Studio 2015 Go to menu click File> New> Project then choose . net Core from left menu by selecting ASP.NET Core Web Application like below image. I have chosen an ASP.NET Core sample Template, like the below image. Let's create another project as a simple class library.


1 Answers

Check out this table here : https://github.com/dotnet/standard/blob/master/docs/versions.md

Or in image form :

enter image description here

So you are using UWP version 10, you can only use libraries that use .net standard 1.4. For the .net framework version 4.5.2 you can only use .net standard 1.2.

Developers making libraries on the .net standard should try and keep the version as low as possible so that as many frameworks as possible can use it, but that's not always happening. And to be fair to them, A LOT was missing in those early versions of .net standard.

If you are in control of the class library, you should lower the .net standard targeting version if that's possible (e.g. You don't use anything from higher versions). If the class library is from someone else, you may be out of luck.

like image 80
MindingData Avatar answered Oct 06 '22 00:10

MindingData