When you first created the Hello solution in Visual Studio, you had a choice of two application templates:
  Blank App (Xamarin.Forms Portable)
  Blank App (Xamarin.Forms Shared)
In Xamarin Studio, the choice is embodied in a pair of radio buttons:
  Use Portable Class Library
  Use Shared Library
The first option creates a Portable Class Library (PCL), whereas the second creates a Shared Asset Project (SAP) consisting only of shared code files. The original Hello solution used the PCL template. Now let’s create a second solution named HelloSap with the SAP template. 

原文

  当我们在VS中创建Hello解决方案的时候,可以选择两种类型的项目模板。第一个选项创建的是可移植的类库(PCL),而第二个创建的是共享的资源项目(SAP),仅仅包含一个共享文件。之前的使用的是PCL模板,下面使用SAP模板创建一个解决方案HelloSap。

As you’ll see, everything looks pretty much the same, except that the HelloSap project itself contains only one item: the App.cs file.  

With both the PCL and SAP approaches, code is shared among the five applications, but in decidedly different ways: With the PCL approach, all the common code is bundled into a dynamic-link library that each application project references and binds to at run time. With the SAP approach, the common code files are effectively included with each of the five application projects at build time. By default, the SAP has only a single file named App.cs, but effectively it’s as if this HelloSap project did not exist and instead there were five different copies of this file in the five application projects. 

Some subtle (and not-so-subtle) problems can manifest themselves with the shared library approach: 

The iOS and Android projects have access to pretty much the same version of .NET, but it is not the same version of .NET that the Windows projects use. This means that any .NET classes accessed by the shared code might be somewhat different depending on the platform. As you’ll discover later in this book, this is the case for some file I/O classes in the System.IO namespace. 

You can compensate for these differences by using C# preprocessor directives, particularly #if and #elif. In the projects generated by the Xamarin.Forms template, the various application projects define symbols that you can use with these directives. 

原文

  创建结束后,可以看到HelloSap解决方案中,除了HelloSap这个项目之外,其他的几个项目都和我们使用PCL模板创建出来的类似。

  不管你使用的是PCL还是SAP,都会被另外几个项目所引用,但是二者有着不同之处。如果使用PCL,所有的公共代码是生成到一个动态链接库(dll)中去,然后其他项目在运行的时候去引用这个dll。然而,SAP方法中,在编译的时候公共代码直接包含在其他的几个项目中了。默认情况下SAP项目只有一个cs文件,如果HelloSap这个项目不存在,完全可以在其他项目中包含这个cs文件来代替这个项目。

...

Most of the programs in this book use the PCL approach. This is the recommended approach for Xamarin.Forms and is preferred by many programmers who have been working with Xamarin.Forms for a while. However, the SAP approach is also supported and definitely has its advocates as well. Programs within these pages that demonstrate the SAP approach always contain the letters Sap at the end of their names, such as the HelloSap program. 

But why choose? You can have both in the same solution. If you’ve created a Xamarin.Forms solution with a Shared Asset Project, you can add a new PCL project to the solution by selecting the Class Library (Xamarin.Forms Portable) template. The application projects can access both the SAP and PCL, and the SAP can access the PCL as well. 

原文

  这本书的大部分示例程序使用的是PCL方法,它是Xamarin.Froms推荐的方法,并且是多数开发者一直所使用的。但是,这两个项目可以同时包含在一个解决方案中。

PCL还是SAP?的更多相关文章

  1. 使用Xamarin.Forms平台开发移动应用指南

    下载书:链接: http://pan.baidu.com/s/1c29H9KG 密码: 7esm 注:捣鼓虚拟机把Hyper-V关闭,后来Xamarin搞挂了,所以暂停翻译. 第1章 Xamarin. ...

  2. 使用C#和.NET的原因

    早在2000年6月,微软公布.NET之后不久,Ximian公司诞生了一个开源项目叫做Mono,运行在Linux环境下面的C#编译器和.NET Framework.十年后,在2011年,Ximian的创 ...

  3. Xamarin.Forms介绍

    On May 28, 2014, Xamarin introduced Xamarin.Forms, which allows you to write user-interface code tha ...

  4. 在Label中显示一段文字

    Let’s create a new Xamarin.Forms PCL solution, named Greetings, using the same process described abo ...

  5. Xamarin.Forms入门学习路线

    Xamarin 介绍 Xamarin是一套跨平台解决方案,目的是使用C#语言创造原生的iOS,Android,Mac和Windows应用. Xamarin的三个优势: Xamarin App拥有原生A ...

  6. Xamarin.Forms 调用 腾讯地图SDK

    Xamarin.Forms研究了好一段时间了,最近一直在学习中,想尝试一下调用其他的SDK,就如腾讯地图SDK(申请容易). 完成此次项目得感谢以下链接: http://www.cnblogs.com ...

  7. 基于传统方法点云分割以及PCL中分割模块

      之前在微信公众号中更新了以下几个章节 1,如何学习PCL以及一些基础的知识 2,PCL中IO口以及common模块的介绍 3,PCL中常用的两种数据结构KDtree以及Octree树的介绍    ...

  8. Xamarin+Prism开发详解一:PCL跨平台类库与Profile的关系

    在[Xamarin+Prism小试牛刀:定制跨平台Outlook邮箱应用]中提到过以下错误,不知道大伙还记得不: 无法安装程序包"Microsoft.Identity.Client 1.0. ...

  9. SAP CRM 性能小技巧

    导言 本页面打算收集SAP CRM实施中可以用于避免性能问题的注意事项,重要的事项会由图标标识. 如果你有其他的技巧想要说出来,别犹豫! 性能注意事项 通用 缓存读取类访问,特别是在性能关键的地方,比 ...

随机推荐

  1. 第十二章 非对称加密算法-RSA

    注意:本节内容主要参考自<Java加密与解密的艺术(第2版)>第8章“高等加密算法--非对称加密算法” 12.1.RSA(最经典的非对称加密算法) 特点: 使用一套密钥即可完成加解密(与D ...

  2. 在 Linux 中用 nmcli 命令绑定多块网卡

    今天,我们来学习一下在 CentOS 7.x 中如何用 nmcli(Network Manager Command Line Interface:网络管理命令行接口)进行网卡绑定. 网卡(接口)绑定是 ...

  3. Java类文件最大限制

    今天在往一个jsp文件里添加代码时,项目跑起来访问这个jsp时报错.. The code of method _jspService(HttpServletRequest, HttpServletRe ...

  4. 网络编程:Http通信与Socket通信

    http://note.youdao.com/share/?id=f14d304548003f65e34255d3ddf9df31&type=note 网络编程:Http通信与Socket通信 ...

  5. Java 获取网络重定向文件的真实URL

    其实Java 使用HttpURLConnection下载的的时候,会自动下载重定向后的文件,但是我们无法获知目标文件的真实文件名,文件类型,用下面的方法可以得到真实的URL,下面是一个YOUKU视频的 ...

  6. webshell

    webshell就是以asp.php.jsp或者cgi等网页文件形式存在的一种命令执行环境,也可以将其称做为一种网页后门.黑客在入侵了一个网站后,通常会将asp或php后门文件与网站服务器WEB目录下 ...

  7. LeetCode189——Rotate Array

    Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array  ...

  8. Modbus工业协议在Android中的应用

    现在工业信息画发展,很多工厂都需要做信息化展示,通常都是利用Android一体机来进行展示和交互. Modbus协议是全球第一个用于工业现场的总线协议,与外设交互可以采用串口通信,tcp等方式:通常在 ...

  9. ACE - Reactor源码总结整理

    ACE源码约10万行,是c++中非常大的一个网络编程代码库,包含了网络编程的边边角角. ACE代码可以分三个层次:OS层.OO层和框架层: OS层主要是为了兼容各个平台,将网络底层API统一化,这一层 ...

  10. php通用安装程序,导入数据文件(.sql)的安装程序

    php通用安装程序,导入数据文件(.sql)的安装程序 该程序只需要1个php文件 和 1个数据文件,很方便调用.install/index.php         程序文件install/mycms ...