简体   繁体   English

我可以在wpf应用程序中使用网络核心库吗?

[英]Can I use a net core library in a wpf application?

I am trying to develop a very simple WCF application. 我正在尝试开发一个非常简单的WCF应用程序。 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. WCF服务器将位于Windows 10计算机中,我想通过Windows 10计算机中的WPF应用程序使用此服务,并且我还希望使用Xamarin拥有另一个适用于Android的应用程序。

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 . 在Visual Studio中,我看到可以创建一个Net Core库,并且看到Net core与WCF兼容, 我可以在此Web中看到

Also I know that Net Core can be run in Windows, Linux and Mac. 我也知道Net Core可以在Windows,Linux和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. 因此,我想知道是否可以开发一个Net core库来开发客户端,以便可以在WPF和Android应用程序中使用它。

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. 我的疑问是,当我在WPF应用程序中向Net Core库项目添加引用时,看到一个黄色三角形,一个警告,因此我猜WPF无法使用Net Core库。

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. 所以我在想,也许对于WCF层,我必须创建一个可由WPF应用程序和Android应用程序使用的Net Standard项目。 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. 但是我想知道这是唯一的方法还是WPF应用程序可以某种方式使用Net Core库而无需使用诸如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. 对于服务器,我也考虑使用Net Core,因为其他任何项目都不会引用该项目,并且Windows中可以使用Net Core。

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. 好了,您应该创建一个.Net标准类库(因此, 不是 .Net Core),在其中放置WCF客户端代码,然后可以从.Net Core或.Net Full项目中引用它。 a .Net Standard Class Library will give you most flexibility so it is the recommended project type for shared libraries. .Net标准类库将为您提供最大的灵活性,因此它是共享库的推荐项目类型。

But according to the docs, see last line you will need to use .Net Full for the server side: 但是根据文档,请参阅最后一行,您将需要在服务器端使用.Net Full:

WCF service applications should still be created with the full .NET Framework version. WCF服务应用程序仍应使用完整的.NET Framework版本创建。

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. 但是我想知道这是唯一的方法还是WPF应用程序可以某种方式使用Net Core库而无需使用诸如Net Standard之类的中间项目。

No. A WPF application targeting .NET Framework cannot reference a .NET Core project. 否。面向.NET Framework的WPF应用程序无法引用.NET Core项目。

.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. 当前处于预览状态的 .NET Core 3确实支持WPF,这意味着您可以从以.NET Core为目标的WPF应用程序中引用.NET Core项目。 But an application targeting .NET Framework cannot reference a library that targets .NET Core and vice versa. 但是,面向.NET Framework的应用程序无法引用针对.NET Core的库,反之亦然。

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. 您应该更喜欢在类库项目中定位.NET Standard,因为它们可以从面向.NET Framework或.NET Core的应用程序中使用。

WPF / Winforms applications are not supported on .Net Core platform yet. .Net Core平台尚不支持WPF / Winforms应用程序。

Present: 当下:

By yet, I mean .Net core 2.x versions. 到目前为止,我的意思是.Net core 2.x版本。

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. 因此,如果您的应用程序不基于.net core的2.x标准,则将无法引用.net core程序集。

Future: 未来:

.Net core 3 preview is available and Winforms / WPF applications are now available on the .Net core platform. .Net核心3预览可用,而.Net核心平台上现在提供Winforms / WPF应用程序。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在.Net Framework 4.6.2应用程序中使用.Net核心类库(.NetStandard v1.5) - How can I use .Net Core Class Library (.NetStandard v1.5) into .Net Framework 4.6.2 Application 我可以在 Linux 中编译 .net Core 3 WPF 应用程序吗? - Can i compile .net Core 3 WPF application in Linux? 如何在.NET核心应用程序中使用.NET核心类库? - How do I use a .NET core class library in a .NET core application? 我可以在 dot net core 控制台应用程序中使用 BackgroundService - Can I use BackgroundService in dot net core console application 我可以在标准.Net应用程序中使用PCL库吗? - Can I use PCL library in standard .Net application? 如何在 WPF .NET 核心应用程序中启用控制台? - How do I enable the console in a WPF .NET Core application? .NET 4.7.1项目不能使用.NET Core 2.0库 - .NET 4.7.1 project can't use .NET Core 2.0 library 我可以将对System.Core.dll(.net 3.5)的引用添加到.net 2.0应用程序并使用它吗 - Can I add a reference to System.Core.dll (.net 3.5) to a .net 2.0 application and use it 我可以在.net核心Web应用程序中使用任何旧的任意WIndows库吗? - Can I use any old arbitrary WIndows library in a .net core web app? 可以将.net 3.5二进制文件用于具有.net 4.0应用程序的库吗? - can I use .net 3.5 binaries for a library with a .net 4.0 application / what are the negatives if any?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM