简体   繁体   English

我是否可以仅使用Xamarin PCL来定位iOS和Android并具有更多.NET功能?

[英]Can I target iOS and Android only with a Xamarin PCL and have more .NET features?

I need to create a library in Xamarin that targets iOS and Android only. 我需要在Xamarin中创建一个仅针对iOS和Android的库。 I do not need to support any other platforms, but I need as much .NET features as possible. 我不需要支持任何其他平台,但我需要尽可能多的.NET功能。

I see that in Change Targets dialog there is no way to uncheck Silverlight check-box: 我看到在Change Targets对话框中无法取消选中Silverlight复选框:

在此输入图像描述

Can I create a Xamarin portable class library that targets iOS and Android only without Silverlight support and have more .NET features supported? 我是否可以创建一个Xamarin便携式类库,仅针对iOS和Android而不支持Silverlight并支持更多.NET功能?

EDIT: Here are some classes that I need to support: X509CertificateCollection, SerializationInfo, NameValueCollection. 编辑:这是我需要支持的一些类:X509CertificateCollection,SerializationInfo,NameValueCollection。 I also need System.Web.Services namespace support. 我还需要System.Web.Services名称空间支持。 It looks like I can use all these in iOS and Android projects directly. 看起来我可以直接在iOS和Android项目中使用所有这些。 Can I create PCL with all these features? 我可以创建具有所有这些功能的PCL吗?

Profile24, which includes Silverlight is the narrowest you are going to get while include Xamarin.iOS and Xamarin.Android Profile24,其中包括Silverlight是你将获得的最窄,包括Xamarin.iOSXamarin.Android

FYI: I totally agree with Matt's suggestion of using Profile111 if you are going the PCL library direction. 仅供参考:我完全同意Matt关于使用Profile111的建议,如果您要进入PCL库方向。 Sometimes for our projects, it is "faster" ($/time) to just go with "Shared Projects" and use #if/#else/#end in the shared code when needed. 有时对于我们的项目,只需使用“共享项目”并在需要时在共享代码中使用#if /#else / #end,就会“更快”($ / time)。 PCL libraries are great for sharing, but if you do not need the heartache of leaving framework pieces behind, the shared project direction can solve today's problem today... ;-) PCL库非常适合共享,但如果你不需要留下框架片的心痛,那么共享的项目方向今天可以解决今天的问题...... ;-)

As of the Xamarin 4.1 release two new profiles were added: 从Xamarin 4.1版本开始,添加了两个新的配置文件:

Profile 44  (.NET Framework 4.5.1, Windows 8.1) (netstandard 1.2)
Profile 151 (.NET Framework 4.5.1, Windows 8.1, Windows Phone 8.1) (netstandard 1.2)

Old ones: 旧的:

Profile 5   (.NET Framework 4,     Windows 8)
Profile 6   (.NET Framework 4.0.3, Windows 8)
Profile 7   (.NET Framework 4.5,   Windows 8)
Profile 14  (.NET Framework 4,     Silverlight 5)
Profile 19  (.NET Framework 4.0.3, Silverlight 5)
Profile 24  (.NET Framework 4.5,   Silverlight 5)
Profile 37  (.NET Framework 4,     Silverlight 5, Windows 8)
Profile 42  (.NET Framework 4.0.3, Silverlight 5, Windows 8)
Profile 47  (.NET Framework 4.5,   Silverlight 5, Windows 8)
Profile 49  (.NET Framework 4.5,   Windows Phone Silverlight 8)
Profile 78  (.NET Framework 4.5,   Windows 8, Windows Phone Silverlight 8)
Profile 92  (.NET Framework 4,     Windows 8, Windows Phone 8.1)
Profile 102 (.NET Framework 4.0.3, Windows 8, Windows Phone 8.1)
Profile 111 (.NET Framework 4.5,   Windows 8, Windows Phone 8.1)
Profile 136 (.NET Framework 4,     Silverlight 5, Windows 8, Windows Phone Silverlight 8)
Profile 147 (.NET Framework 4.0.3, Silverlight 5, Windows 8, Windows Phone Silverlight 8)
Profile 158 (.NET Framework 4.5,   Silverlight 5, Windows 8, Windows Phone Silverlight 8)
Profile 225 (.NET Framework 4,     Silverlight 5, Windows 8, Windows Phone 8.1)
Profile 255 (.NET Framework 4.5,   Silverlight 5, Windows 8, Windows Phone 8.1)
Profile 259 (.NET Framework 4.5,   Windows 8, Windows Phone 8.1, Windows Phone Silverlight 8)
Profile 328 (.NET Framework 4,     Silverlight 5, Windows 8, Windows Phone 8.1, Windows Phone Silverlight 8)
Profile 336 (.NET Framework 4.0.3, Silverlight 5, Windows 8, Windows Phone 8.1, Windows Phone Silverlight 8)
Profile 344 (.NET Framework 4.5,   Silverlight 5, Windows 8, Windows Phone 8.1, Windows Phone Silverlight 8)

http://danrigby.com/2014/05/14/supported-pcl-profiles-xamarin-for-visual-studio-2/ http://danrigby.com/2014/05/14/supported-pcl-profiles-xamarin-for-visual-studio-2/

While you will be limited if you try to target PCL, another option is to use a Bait-and-Switch NuGet, which would be setup as follows: 如果您尝试定位PCL,您将受到限制,另一种选择是使用Bait-and-Switch NuGet,其设置如下:

  • Shared Project - Contains all your shared code 共享项目 - 包含所有共享代码
  • Android Library Project - References Shared Project, so it gets all the code Android库项目 - 引用共享项目,因此它获取所有代码
  • iOS Library Project - References Shared Project, so it gets all the code iOS库项目 - 引用共享项目,因此它获取所有代码
  • PCL Project - Empty project, which only contains empty stubs for the methods PCL项目 - 空项目,仅包含方法的空存根

Then you create a NuGet, where the Android payload is the Android Library project, and the iOS payload is the iOS Library project. 然后创建一个NuGet,其中Android有效负载是Android Library项目,iOS有效负载是iOS Library项目。

The PCL project then only surfaces the API that is PCL compatible, but the implementation happens to use everything you need. 然后,PCL项目只显示与PCL兼容的API,但实现恰好使用了您需要的所有内容。

For bait-and-switch approach see: http://log.paulbetts.org/the-bait-and-switch-pcl-trick/ 对于诱饵和转换方法,请参阅: http//log.paulbetts.org/the-bait-and-switch-pcl-trick/

PCL profile is (nearly) the same, including or not Silverlight, you have only acces to the PCL assemblies. PCL配置文件(几乎)相同,包括或不包括Silverlight,您只能访问PCL程序集。

But, Xamarin Forms already allows you to cope with that, on each platform you have a .Droid and .iOS project, and on these projects you can use the full .net framework. 但是,Xamarin Forms已经允许您应对这一点,在每个平台上都有.Droid和.iOS项目,在这些项目中,您可以使用完整的.net框架。

To access the code from these projects you have the Dependency Services , and if you want to use the same code for both, Android and iOS you have shared projects . 要从这些项目中访问代码,您需要具有Dependency Services ,如果您想为Android和iOS使用相同的代码,则您可以共享项目

So basically, put all your shared coded in a shared project, implement an interface, register it as a dependency service, retrieve it in your Forms code and in this way you will get support for the full framework. 基本上,将所有共享编码放在共享项目中,实现接口,将其注册为依赖服务,在Forms代码中检索它,这样您就可以获得对完整框架的支持。

As the text tells you, it will automatically add silverlight because there will be no cut in functionality. 正如文本告诉你的那样,它将自动添加silverlight,因为不会削减功能。 So there will be no more features available. 因此将不再有可用的功能。

On the other side, I would propose using Profile111 (see list in SushiHangover's answer). 另一方面,我建议使用Profile111 (参见SushiHangover答案中的列表)。 On the one side this allows you later adding Windows 10 as a target platform and also most PCLs seem to support this profile, since Silverlight is going to die (Silverlight 5 was last and Windows Phone is UWP) 一方面,这允许您稍后将Windows 10添加为目标平台,并且大多数PCL似乎都支持此配置文件,因为Silverlight将会死(Silverlight 5是最后一个,Windows Phone是UWP)

暂无
暂无

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

相关问题 Xamarin PCL和HttpClient的Microsoft.Net.Http在Android AND iOS上受支持吗? - Xamarin PCL and Microsoft.Net.Http for HttpClient is this supported on Android AND iOS? 在pcl中使用TcpClient进行Xamarin定位ios和android - Using TcpClient in pcl for xamarin targeting ios and android 无法将Xamarin.Android和Xamarin.iOS添加到PCL - Unable to add Xamarin.Android and Xamarin.iOS to PCL 我如何使用PCL项目在Xamarin中为Android和iOS开发应用程序? - How do i Use a PCL project to develop an app for Android and iOS in Xamarin? 如何使用xamarin forme pcl解决方案在iOS上运行通知? - How can I get notifications to work on iOS, using xamarin forme pcl soluction? 我可以在 Android 中只有一个没有全屏的 Xamarin 内容页面吗? - Can I have only one Xamarin Content Page with no full screen in Android? 在DNX项目中,我如何定位Xamarin Android? - In a DNX project, how can I target for Xamarin Android? 如何在我的 iOS 和 Android 项目中用 .NET MAUI NuGet 包替换我的 Xamarin NuGet 包? - How can I replace my Xamarin NuGet packages with .NET MAUI NuGet packages in my iOS and Android projects? 如何在Xamarin中的PCL代码上创建和运行测试? - How can I create and run tests on PCL code in Xamarin? 无法将System.Net.Sockets添加到Xamarin PCL项目中,可以使用“诱饵和切换”高级PCL方法来完成吗? - Can't add System.Net.Sockets to a Xamarin PCL project can this be done using “Bait and switch” advanced PCL approach?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM