Use System.Net.Sockets in PCL (.Net 4.5 + phone 8)

烈酒焚心 提交于 2019-12-23 15:05:04

问题


I have existing .Net libraries which work already for .Net 4.5 and Windows Phone 8. Now I would like to convert this in a portable class library and suddenly I can't use System.Net.Sockets anymore.

I only cheched .Net 4.5 and windows phone 8. Xbox/store app/silverlight is not selected. Xamarin is automaticly selected because it has the same requirements.

I can avoid sockets by using interfaces and stuff, but why can't I use it if they both support it?

There are other questions on stackoverflow about this but these use xbox or metro apps.


回答1:


It seems the WinRT API is added to PCL:

https://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/4443287-make-winrt-api-usable-in-portable-class-libraries

Make WinRT API usable in Portable Class Libraries targeting Windows 8 and WP8

That’s a great suggestion. We’ve added this capability for the new versions of both platforms. So when you author a portable class libraries with the following targets (or any subset) you’ll have access to WinRT APIs as well:

  • Windows 8.1
  • Windows Phone 8.1
  • Windows Phone Silverlight 8.1 For the first two platforms, you’re also able to produce Windows Runtime components (WinMD).

Immo Landwerth
Program Manager
.NET Framework Team

You need VS2013 Update 2 for this.
Here some more info about this update:
http://blogs.msdn.com/b/somasegar/archive/2014/04/02/visual-studio-2013-update-2-rc-universal-projects-for-windows-and-windows-phone.aspx

Sockets in WinRT is in the Windows.Networking.Sockets namespace:
http://msdn.microsoft.com/en-us/library/windows/apps/br226960.aspx



来源:https://stackoverflow.com/questions/22131737/use-system-net-sockets-in-pcl-net-4-5-phone-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!