简体   繁体   中英

Can I use a net core library in a wpf application?

I am trying to develop a very simple WCF application. The WCF server will be in a windows 10 computer and I would like to consume this service with a WPF application in a windows 10 computer and also I would like to have another application for android, using Xamarin.

In visual studio I see that I can create a Net Core library and also I see that Net core is compatible with WCF, I can see in this web .

Also I know that Net Core can be run in Windows, Linux and Mac. So I am wondering if I could develop a Net core Library to develop the client so I could use it in my WPF and Android applications.

My doubt it is when I add a reference in my WPF application to the net Core library project, I see a yellow triangle, a warning, so I guess that WPF can't use the Net Core library.

So I was thinking that perhaps, for the WCF layer, I would have to create a Net Standard project that can be use by the WPF application and the Android application. But I would like to know if this is the unique way or there are some way that a WPF application can use a Net Core library without needed to use a middle project like Net Standard.

For the server, I was thinking to use Net Core too, because this project will not be referenced by any other project and Net Core can be used in windows.

Well, you should create a .Net Standard Class Library (So, not .Net Core), put in your WCF clientside code in there and you can reference it from a .Net Core or .Net Full project. a .Net Standard Class Library will give you most flexibility so it is the recommended project type for shared libraries.

But according to the docs, see last line you will need to use .Net Full for the server side:

WCF service applications should still be created with the full .NET Framework version.

But I would like to know if this is the unique way or there are some way that a WPF application can use a Net Core library without needed to use a middle project like Net Standard.

No. A WPF application targeting .NET Framework cannot reference a .NET Core project.

.NET Core 3, which is currently in preview , does however support WPF which means that you can reference a .NET Core project from a WPF application that targets .NET Core. But an application targeting .NET Framework cannot reference a library that targets .NET Core and vice versa.

You should prefer to target .NET Standard in your class library projects since these can then be consumed from applications targeting either .NET Framework or .NET Core.

WPF / Winforms applications are not supported on .Net Core platform yet.

Present:

By yet, I mean .Net core 2.x versions.

So, if your application is NOT based on 2.x standard of .net core, you will NOT be able to reference the .net core assembly.

Future:

.Net core 3 preview is available and Winforms / WPF applications are now available on the .Net core platform.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM